## 2020年6月15日月曜日

### 数学 - Python - 代数学 - 1次関数、2次関数 - 通る点、頂点、直線、x軸、接点、判別式

1. 頂点座標 が （3，-1）の2次関数は

$y=a{\left(x-3\right)}^{2}-1$

これが点（4，2）を 通ればいいのでもある放物線は

$\begin{array}{l}2=a{\left(4-3\right)}^{2}-1\\ a=3\\ y=3{\left(x-3\right)}^{2}-1\\ =3{x}^{2}-18x+26\end{array}$

2. $y=a{x}^{2}+bx+c$
$\left\{\begin{array}{l}{b}^{2}-4ac=0\\ a+b+c=1\\ 16a+4b+c=4\end{array}$
$\begin{array}{l}c=1-a-b\\ 16a+4b+1-a-b=4\\ 15a+3b=3\\ b=\frac{3-15a}{3}=1-5a\\ c=1-a-1+5a=4a\end{array}$
$\begin{array}{l}{\left(1-5a\right)}^{2}-16{a}^{2}=0\\ 1-10a+25{a}^{2}-16{a}^{2}=0\\ 9{a}^{2}-10a+1=0\\ a=\frac{5±\sqrt{25-9}}{9}\\ =\frac{5±4}{9}\\ =1,\frac{1}{9}\end{array}$
$\begin{array}{l}b=-4,\frac{4}{9}\\ c=4,\frac{4}{9}\end{array}$
$\begin{array}{l}y={x}^{2}-4x+4\\ y=\frac{1}{9}{x}^{2}+\frac{4}{9}x+\frac{4}{9}\end{array}$

3. $\begin{array}{l}y=a{x}^{2}+bx+c\\ =a{\left(x+\frac{b}{2a}\right)}^{2}-\frac{{b}^{2}-4ac}{4a}\end{array}$
$\left\{\begin{array}{l}4=a-b+c\\ -8=4a+2b+c\\ 2\left(-\frac{b}{2a}\right)-4\left(-\frac{{b}^{2}-4ac}{4a}\right)+27=0\end{array}$
$\begin{array}{l}12=-3a-3b\\ a=\frac{-12-3b}{3}=-b-4\end{array}$
$\begin{array}{l}4=-b-4-b+c\\ c=2b+8\end{array}$
$-b+{b}^{2}-4ac+27a=0$
$-b+{b}^{2}-4\left(-b-4\right)\left(2b+8\right)+27\left(-b-4\right)=0$
$\begin{array}{l}-b+{b}^{2}+8\left({b}^{2}+8b+16\right)-27b-108=0\\ 9{b}^{2}+36b+20=0\\ b=\frac{-18±12}{9}=-\frac{10}{3},-\frac{2}{3}\end{array}$
$\begin{array}{l}a=-\frac{2}{3},-\frac{10}{3}\\ c=\frac{4}{3},\frac{20}{3}\end{array}$
$\begin{array}{l}y=-\frac{2}{3}{x}^{2}-\frac{10}{3}x+\frac{4}{3}\\ y=-\frac{10}{3}{x}^{2}-\frac{2}{3}x+\frac{20}{3}\end{array}$

コード

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

print('6.')

p = plot(3 * x ** 2 - 18 * x + 26,
-1, 2,
x ** 2 - 4 * x + 4,
x ** 2 / 9 + 4 * x / 9 + Rational(4, 9),
1, 4,
-2 * x ** 2 / 3 - 10 * x / 3 + Rational(4, 3),
-10 * x ** 2 / 3 - 2 * x / 3 + Rational(20, 3),
(2 * x + 27) / 4,
-8,
(x, -10, 10),
ylim=(-10, 10),
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('sample6.png')
p.show()


% ./sample6.py
6.
%