## 2019年5月12日日曜日

### 数学 - Python - 関連しながら変化する世界 - 簡単な関数 - 分数関数・無理関数 - y = (ax + b)/(cx + d)のグラフ(式の変形、商と剰余、漸近線、軸との交点)

1. $\begin{array}{l}y\\ =\frac{3x}{x-1}\\ =\frac{3\left(x-1\right)+3}{x-1}\\ =\frac{3}{x-1}+3\end{array}$

よって漸近線は

$x=1,y=3$

グラフ。

2. $\begin{array}{l}y=\frac{2x+1}{x+1}\\ =\frac{2\left(x+1\right)-1}{x+1}\\ =-\frac{2}{x+1}+2\\ x=-1,y=2\end{array}$

3. $\begin{array}{l}y=\frac{-2\left(x-2\right)-1}{x-2}\\ =-\frac{1}{x-2}-2\\ x=2,y=-2\end{array}$

4. $\begin{array}{l}y=\frac{-2x+3}{2x+1}\\ =\frac{-\left(2x+1\right)+4}{2x+1}\\ =\frac{4}{2x+1}-1\\ =\frac{2}{x+\frac{1}{2}}-1\\ x=-\frac{1}{2},y=-1\end{array}$

コード

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, solve, plot

print('30.')

x = symbols('x')
fs = [3 * x / (x - 1), (2 * x + 1) / (x + 1), (3 - 2 * x) / (x - 2),
(-2 * x + 3) / (2 * x + 1),
3, 2, -2, -1]

for i, f in enumerate(fs[:4], 1):
print(f'({i})')
pprint(solve(f, dict=True))
print()

p = plot(*fs,
ylim=(-10, 10),
legend=False,
show=False)

colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'gray', 'skyblue', 'yellow']

for o, color in zip(p, colors):
o.line_color = color

p.show()
p.save('sample30.png')


C:\Users\...>py sample30.py
30.
(1)
[{x: 0}]

(2)
[{x: -1/2}]

(3)
[{x: 3/2}]

(4)
[{x: 3/2}]

C:\Users\...>