## 2019年7月5日金曜日

### 数学 - Python - 解析学 - 微分法 - 関数の凹凸 - 3次関数の変曲点の個数

1. $\begin{array}{l}f\text{'}\left(x\right)=3{x}^{2}+2ax+b\\ f\text{'}\text{'}\left(x\right)=6x+2a\\ 6x+2a=0\\ x=\frac{1}{3}a\end{array}$

よって、 任意の3次関数はただ1つの変曲点をもつ。

（証明終）

コード

Python 3

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

print('2.')
x = symbols('x')
a = []
n = 5
for _ in range(n):
while True:
r = random.randrange(-5, 6)
if r != 0:
a.append(r)
break
fs = [sum([a[i] * x ** 3] + [x ** k for k in range(3)])
for i in range(n)]

for f in fs:
d = Derivative(f, x, 2)
for o in [d, d.doit(), solve(d.doit(), x)]:
pprint(o)
print()
ds = [Derivative(f, x, 2).doit() for f in fs]
p = plot(*fs, *ds,
(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('sample2.png')


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

2⋅(1 - 9⋅x)

[1/9]

2
d ⎛   3    2        ⎞
───⎝- x  + x  + x + 1⎠
2
dx

2⋅(1 - 3⋅x)

[1/3]

2
d ⎛   3    2        ⎞
───⎝- x  + x  + x + 1⎠
2
dx

2⋅(1 - 3⋅x)

[1/3]

2
d ⎛   3    2        ⎞
───⎝5⋅x  + x  + x + 1⎠
2
dx

2⋅(15⋅x + 1)

[-1/15]

2
d ⎛   3    2        ⎞
───⎝5⋅x  + x  + x + 1⎠
2
dx

2⋅(15⋅x + 1)

[-1/15]

C:\Users\...>