## 2019年5月24日金曜日

### 数学 - Python - 関連しながら変化する世界 - 簡単な関数 - 分数関数・無理関数 - 簡単な無理方程式・無理不等式(直線との交点座標)

1. $\begin{array}{l}2x+3=9\\ x=3\end{array}$

よって 求める交点座標は

$\left(3,3\right)$

2. $\begin{array}{l}x={\left(x-6\right)}^{2}\\ {x}^{2}-13x+36=0\\ \left(x-9\right)\left(x-4\right)=0\\ \left(4,-2\right)\end{array}$

3. $\begin{array}{l}4-2x={\left(2-x\right)}^{2}\\ {x}^{2}-2x=0\\ x=0,2\\ \left(0,2\right),\left(2,0\right)\end{array}$

4. $\begin{array}{l}x-2=\frac{1}{9}{x}^{2}\\ {x}^{2}-9x+18=0\\ \left(x-3\right)\left(x-6\right)=0\\ \left(3,1\right),\left(6,2\right)\end{array}$

コード

Python 3

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

print('37.')

x = symbols('x')

ts = [(sqrt(2 * x + 3), 3),
(-sqrt(x), x - 6),
(sqrt(4 - 2 * x), 2 - x),
(sqrt(x - 2), x / 3)]

for i, (l, r) in enumerate(ts, 1):
print(f'({i})')
xs = solve(l - r)
for x0 in xs:
print(f'({x0}, {l.subs({x:x0})})')
print()

fs = []
for a, b in ts:
fs += [a, b]
p = plot(*fs, ylim=(-10, 10), legend=True, 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('sample37.png')

C:\Users\...>py sample37.py
37.
(1)
(3, 3)

(2)
(4, -2)

(3)
(0, 2)
(2, 0)

(4)
(3, 1)
(6, 2)

C:\Users\...>