## 2019年4月5日金曜日

### 数学 - Python - 解析学 - 級数 - テイラーの公式 - 指数関数(平方、立方、4次、剰余項の評価)

1. $\begin{array}{}{e}^{2}<{3}^{2}\\ \left|{R}_{5}\right|\\ \le {e}^{2}·\frac{{2}^{5}}{5!}\\ \le {3}^{2}·\frac{{2}^{5}}{5!}\\ =\frac{3·{2}^{2}}{5}\\ =\frac{12}{5}\end{array}$

2. $\begin{array}{}{e}^{3}<{3}^{3}\\ \left|{R}_{5}\right|\\ \le {e}^{3}·\frac{{3}^{5}}{5!}\\ \le {3}^{3}·\frac{{3}^{5}}{5!}\\ =\frac{{3}^{7}}{5·4·2}\\ =\frac{2187}{40}\end{array}$

コード

Python 3

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

print('8.')

x = symbols('x')
f = exp(x)
g = sum([Derivative(f, x, i).subs({x: 0}) /
factorial(i) * x ** i for i in range(5)])
for o in [g, g.doit()]:
pprint(o)
print()
xs = [2, 3]
rs = [Rational(12, 5), Rational(2187, 40)]
for i, (x0, r0) in enumerate(zip(xs, rs)):
print(f'({chr(ord("a") + i)}) x = {x0}')
gx = g.subs({x: x0})
r = (exp(x0) - gx).doit()
for o in [gx, float(r), r0, r <= r0]:
pprint(o)
print()

p = plot(f, g.doit(), (x, -5, 5), ylim=(0, 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('sample8.png')


C:\Users\...>py sample8.py
8.
⎛  4    ⎞│         ⎛  3    ⎞│         ⎛  2    ⎞│
4 ⎜ d ⎛ x⎞⎟│       3 ⎜ d ⎛ x⎞⎟│       2 ⎜ d ⎛ x⎞⎟│
x ⋅⎜───⎝ℯ ⎠⎟│      x ⋅⎜───⎝ℯ ⎠⎟│      x ⋅⎜───⎝ℯ ⎠⎟│
⎜  4    ⎟│         ⎜  3    ⎟│         ⎜  2    ⎟│
⎝dx     ⎠│x=0      ⎝dx     ⎠│x=0      ⎝dx     ⎠│x=0     ⎛d ⎛ x⎞⎞│
──────────────── + ──────────────── + ──────────────── + x⋅⎜──⎝ℯ ⎠⎟│    + 1
24                 6                  2             ⎝dx    ⎠│x=0

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

(a) x = 2
⎛  3    ⎞│        ⎛  4    ⎞│
⎜ d ⎛ x⎞⎟│        ⎜ d ⎛ x⎞⎟│
4⋅⎜───⎝ℯ ⎠⎟│      2⋅⎜───⎝ℯ ⎠⎟│
⎛  2    ⎞│        ⎜  3    ⎟│        ⎜  4    ⎟│
⎛d ⎛ x⎞⎞│        ⎜ d ⎛ x⎞⎟│        ⎝dx     ⎠│x=0     ⎝dx     ⎠│x=0
2⋅⎜──⎝ℯ ⎠⎟│    + 2⋅⎜───⎝ℯ ⎠⎟│    + ─────────────── + ─────────────── + 1
⎝dx    ⎠│x=0     ⎜  2    ⎟│             3                 3
⎝dx     ⎠│x=0

0.38905609893065024

12/5

True

(b) x = 3
⎛  2    ⎞│        ⎛  3    ⎞│         ⎛  4    ⎞│
⎜ d ⎛ x⎞⎟│        ⎜ d ⎛ x⎞⎟│         ⎜ d ⎛ x⎞⎟│
9⋅⎜───⎝ℯ ⎠⎟│      9⋅⎜───⎝ℯ ⎠⎟│      27⋅⎜───⎝ℯ ⎠⎟│
⎜  2    ⎟│        ⎜  3    ⎟│         ⎜  4    ⎟│
⎛d ⎛ x⎞⎞│        ⎝dx     ⎠│x=0     ⎝dx     ⎠│x=0      ⎝dx     ⎠│x=0
3⋅⎜──⎝ℯ ⎠⎟│    + ─────────────── + ─────────────── + ──────────────── + 1
⎝dx    ⎠│x=0          2                 2                 8

3.710536923187668

2187
────
40

True

C:\Users\...>