## 2020年6月29日月曜日

### 数学 - Python - 放物線・だ円・双曲線 - 2次関数 - 放物線・だ円・双曲線 - 放物線 - 方程式、焦点、準線

1. $\begin{array}{l}y={x}^{2}\\ =\frac{1}{4·\frac{1}{4}}{x}^{2}\end{array}$

よって焦点、準線はそれぞれ

$\begin{array}{l}\left(0,\frac{1}{4}\right)\\ y=-\frac{1}{4}\end{array}$

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

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

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

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

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

コード

#!/usr/bin/env python3
from sympy import sqrt, plot, Rational
from sympy.abc import x, y

print('2.')

ts = [(x ** 2, -Rational(1, 4)),
(x ** 2 / 12, -3),
(-x ** 2 / 2, Rational(1, 2))] + \
[[s * sqrt(y) for s in [-1, 1]]
for y in [4 * x, -x, 8 * x]]
for i, t in enumerate(ts, 1):
print(f'({i})')
p = plot(*t,
(x, -5, 5),
ylim=(-5, 5),
legend=True,
show=False)
colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']
for o, color in zip(p, colors):
o.line_color = color
p.save(f'sample2_{i}.png')
p.show()


% ./sample2.py
2.
(1)
(2)
(3)
(4)
(5)
(6)
%