## 2019年9月8日日曜日

### 数学 - Python - 微分積分学 - 微分法 - 極値、極大値、極小値、最大値、最小値、累乗(べき乗、平方、2次)、平方根、逆数

1. $\begin{array}{l}f\text{'}\left(x\right)\\ =-2+6x\\ =2\left(3x-1\right)\\ f\text{'}\left(\frac{1}{3}\right)=0\\ x<\frac{1}{3}\\ f\text{'}\left(x\right)<0\\ x>\frac{1}{3}\\ f\text{'}\left(x\right)>0\end{array}$

求める極値は最小値で、

$f\left(\frac{1}{3}\right)=1-\frac{2}{3}+3·\frac{1}{{3}^{2}}=\frac{2}{3}$

2. 極値は最大値で、

$f\left(0\right)=\sqrt{1-{0}^{2}}=1$

3. $\begin{array}{l}f\text{'}\left(x\right)=\frac{1}{2\sqrt{x}}-\frac{4}{{x}^{2}}\\ \frac{1}{2\sqrt{x}}=\frac{4}{{x}^{2}}\\ {x}^{2}=8\sqrt{x}\\ {x}^{4}=64x\\ x\left({x}^{3}-64\right)=0\\ {x}^{3}=64\\ x=4\\ f\text{'}\left(4\right)=0\\ x<4\\ f\text{'}\left(x\right)<0\\ x>4\\ f\left(x\right)>0\end{array}$

よって、極値は最小値で、

$f\left(4\right)=\sqrt{4}+\frac{4}{4}=3$

コード

Python 3

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

x = symbols('x', real=True)
fs = [1 - 2 * x + 3 * x ** 2,
sqrt(1 - x ** 2),
sqrt(x) + 4 / x]
xs = [(-5, 5),
(-1, 1),
(0.1, 5)]
ds = [Derivative(f, x, 1) for f in fs]
ds1 = [d.doit() for d in ds]
s = [solve(d, x) for d in ds1]
for i, (d, d1, t) in enumerate(zip(ds, ds1, s), 21):
print(f'{i}.')
for o in [d, d1, t]:
pprint(o)
print()

extremums = [f.subs({x: t[0]}) for f, t in zip(fs, s)]
p = plot(*[(f, (x, x1, x2)) for f, (x1, x2) in zip(fs, xs)],
*[(extremum, (x, -5, 5)) for extremum in extremums],
ylim=(0, 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('sample21.png')


C:\Users\...>py sample21.py
21.
d ⎛   2          ⎞
──⎝3⋅x  - 2⋅x + 1⎠
dx

6⋅x - 2

[1/3]

22.
⎛   ________⎞
d ⎜  ╱      2 ⎟
──⎝╲╱  1 - x  ⎠
dx

-x
───────────
________
╱      2
╲╱  1 - x

[0]

23.
d ⎛     4⎞
──⎜√x + ─⎟
dx⎝     x⎠

4     1
- ── + ────
2   2⋅√x
x

[4]

c:\Users\...>