## 2019年11月1日金曜日

### 数学 - Python - 微分積分学 - 平均値の定理 - 連続、微分可能、閉区間、開区間、微分

1. $\begin{array}{l}f\text{'}\left(x\right)=2x\\ f\left(a+h\right)=f\left(a\right)+f\text{'}\left(a+\theta h\right)h\\ {\left(a+h\right)}^{2}={a}^{2}+2\left(a+\theta h\right)h\\ {h}^{2}=2\theta {h}^{2}\\ \theta =\frac{1}{2}\end{array}$

（証明終）

コード

Python 3

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

print('1.')

x = symbols('x')
f = x ** 2
f1 = Derivative(f, x, 1).doit()
a, h, theta = symbols('a, h, θ')
eq = f.subs({x: a + h}) - (f.subs({x: a}) + f1.subs({x: a + theta * h}) * h)
for o in [eq, solve(eq, theta)]:
pprint(o)
print()
a = 0
b = 2
h = b - a
p = plot(f, f1.subs({x: a + Rational(h, 2)}) * (x - (a + Rational(h,  2))) + f.subs({x: a + Rational(h, 2)}),
(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.show()
p.save('sample1.png')


% ./sample1.py
1.
2                            2
- a  - h⋅(2⋅a + 2⋅h⋅θ) + (a + h)

[1/2]

%