## 2020年6月1日月曜日

### 数学 - Python - 代数学 - 1次関数、2次関数 - 2次関数の最大と最小 - 頂点

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

よって

$x=2$

のとき最小となり、 その値は3。

2. $y=-{\left(x+3\right)}^{2}+14$

x が-3のとき最大値14。

3. $y=4{\left(x+\frac{3}{2}\right)}^{2}$

よって

$x=-\frac{3}{2}$

のとき最小値0。

4. $\begin{array}{l}y=\frac{3}{4}\left({x}^{2}+8x\right)-12\\ =\frac{3}{4}{\left(x+4\right)}^{2}-24\end{array}$

x が-4のとき最小値-24。

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

6. $\begin{array}{l}y=\frac{1}{3}\left(x-\frac{3}{2}\right)\left(-\frac{1}{2}\right)\left(x-\frac{2}{5}\right)\\ =-\frac{1}{6}\left({x}^{2}-\left(\frac{3}{2}+\frac{2}{5}\right)x\right)-\frac{1}{10}\\ =-\frac{1}{6}\left({x}^{2}-\frac{19}{10}x\right)-\frac{1}{10}\\ =-\frac{1}{6}{\left(x-\frac{19}{20}\right)}^{2}+\frac{1}{6}·{\left(\frac{19}{20}\right)}^{2}-\frac{1}{10}\\ =-\frac{1}{6}{\left(x-\frac{19}{20}\right)}^{2}+\frac{1}{6}·\frac{361}{400}-\frac{1}{10}\\ =-\frac{1}{6}{\left(x-\frac{19}{20}\right)}^{2}+\frac{121}{2400}\end{array}$

7. $\begin{array}{l}y=a\left({x}^{2}-\frac{b}{a}x\right)\\ =a{\left(x-\frac{b}{2a}\right)}^{2}-\frac{{b}^{2}}{4a}\end{array}$

よって

$x=-\frac{b}{2a}$

のとき最小値

$-\frac{{b}^{2}}{4a}$

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

コード

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

print('14.')
x = symbols('x')
ys = [x ** 2 - 4 * x + 7,
4 * x ** 2 + 12 * x + 9,
x * (4 - 3 * x) / 2]
ys0 = [3, 0, Rational(2, 3)]

p = plot(*ys, *ys0,
(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.show()
p.save('sample14.png')


% ./sample14.py
14.
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/sympy/plotting/plot.py:1065: MatplotlibDeprecationWarning:
The set_smart_bounds function was deprecated in Matplotlib 3.2 and will be removed two minor releases later.
self.ax[i].spines['left'].set_smart_bounds(True)
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/sympy/plotting/plot.py:1066: MatplotlibDeprecationWarning:
The set_smart_bounds function was deprecated in Matplotlib 3.2 and will be removed two minor releases later.
self.ax[i].spines['bottom'].set_smart_bounds(False)
%