2019年6月26日水曜日

数学 - Python - 解析学 - 級数 - テイラーの公式 - 指数関数、累乗(べき乗、平方)、差、商、極限

1. $\begin{array}{l}\frac{d}{\mathrm{dx}}\left({e}^{x}-1-x\right)\\ ={e}^{x}-1\\ \frac{{d}^{2}}{{\mathrm{dx}}^{2}}\left({e}^{x}-1-x\right)\\ ={e}^{x}\\ {e}^{x}-1-x=\frac{{x}^{2}}{2!}+\frac{{x}^{3}}{3!}+\dots \\ \underset{n\to 0}{\mathrm{lim}}\frac{{e}^{x}-1-x}{{x}^{2}}=\frac{1}{2!}=\frac{1}{2}\end{array}$

コード

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, plot, Limit, exp

print('29.')

x = symbols('x')
f = (exp(x) - 1 - x) / x ** 2

for dir in ['+', '-']:
l = Limit(f, x, 0, dir=dir)
for o in [l, l.doit()]:
pprint(o)
print()

p = plot(exp(x), -1, -x, x ** 2,
exp(x) - 1 - x, f,
(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('sample29.png')


C:\Users\...>py sample29.py
29.
⎛      x    ⎞
⎜-x + ℯ  - 1⎟
lim ⎜───────────⎟
x─→0⁺⎜      2    ⎟
⎝     x     ⎠

1/2

⎛      x    ⎞
⎜-x + ℯ  - 1⎟
lim ⎜───────────⎟
x─→0⁻⎜      2    ⎟
⎝     x     ⎠

1/2

C:\Users\...>