## 2019年4月2日火曜日

### 数学 - Python - 解析学 - 級数 - テイラーの公式 - 指数関数(5次のテイラー多項式)

1. $\begin{array}{}\frac{d}{\mathrm{dx}}{e}^{-x}=-{e}^{-x}\\ \frac{{d}^{2}}{{\mathrm{dx}}^{2}}{e}^{-x}={e}^{-x}\\ 1-x+\frac{1}{2!}{x}^{2}-\frac{1}{3!}{x}^{3}+\frac{1}{4!}{x}^{4}-\frac{1}{5!}{x}^{5}\end{array}$

コード

Python 3

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

print('5.')

x = symbols('x')
f = exp(x)
g = sum([Derivative(f, x, i).subs({x: 0}) /
factorial(i) * x ** i for i in range(6)])

for o in [f, g, g.doit()]:
pprint(o)
print()

p = plot(f, g.doit(), ylim=(-10, 10), show=False, legend=True)
colors = ['red', 'green', 'blue', 'brown']
for s, color in zip(p, colors):
s.line_color = color
p.show()
p.save('sample5.png')


C:\Users\...>py sample5.py
5.
x
ℯ

⎛  5    ⎞│         ⎛  4    ⎞│         ⎛  3    ⎞│         ⎛  2    ⎞│
5 ⎜ d ⎛ x⎞⎟│       4 ⎜ d ⎛ x⎞⎟│       3 ⎜ d ⎛ x⎞⎟│       2 ⎜ d ⎛ x⎞⎟│
x ⋅⎜───⎝ℯ ⎠⎟│      x ⋅⎜───⎝ℯ ⎠⎟│      x ⋅⎜───⎝ℯ ⎠⎟│      x ⋅⎜───⎝ℯ ⎠⎟│
⎜  5    ⎟│         ⎜  4    ⎟│         ⎜  3    ⎟│         ⎜  2    ⎟│
⎝dx     ⎠│x=0      ⎝dx     ⎠│x=0      ⎝dx     ⎠│x=0      ⎝dx     ⎠│x=0
──────────────── + ──────────────── + ──────────────── + ──────────────── + x⋅
120                 24                 6                  2

⎛d ⎛ x⎞⎞│
⎜──⎝ℯ ⎠⎟│    + 1
⎝dx    ⎠│x=0

5    4    3    2
x    x    x    x
─── + ── + ── + ── + x + 1
120   24   6    2

C:\Users\...>