## 2019年4月6日土曜日

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

1. $\begin{array}{l}{e}^{2}<{3}^{2}=9\\ \frac{{2}^{2}}{2!}=2\\ \frac{{2}^{3}}{3!}=\frac{4}{3}\\ \frac{{2}^{4}}{4!}=\frac{2}{3}\\ \frac{{2}^{5}}{5!}=\frac{4}{15}\\ \frac{{2}^{6}}{6!}=\frac{8}{90}\\ \frac{{2}^{7}}{7!}=\frac{8}{315}\\ \frac{{2}^{8}}{8!}=\frac{2}{315}\\ \frac{{2}^{9}}{9!}=\frac{4}{2835}\\ \frac{{2}^{10}}{10!}=\frac{4}{14175}\\ \frac{{2}^{11}}{11!}=\frac{8}{155925}\\ \frac{{2}^{12}}{12!}=\frac{4}{467775}\\ \left|{R}_{12}\right|\le 9·\frac{4}{467775}<1{0}^{-4}\end{array}$

小数第4位までは12項。

2. $\begin{array}{l}\frac{{2}^{13}}{13!}=\frac{8}{6081075}\\ \frac{{2}^{14}}{14!}=\frac{8}{42567525}\\ \frac{{2}^{15}}{15!}=\frac{16}{638512875}\\ \left|{R}_{15}\right|\\ \le {e}^{2}·\frac{{2}^{15}}{15!}\\ \le {3}^{2}·\frac{{2}^{15}}{15!}\\ <1{0}^{-6}\end{array}$

よって第15項。

コード

Python 3

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

print('9.')

x = symbols('x')
f = exp(x)
n = 0
is_a = False
while True:
n += 1
g = sum([Derivative(f, x, i).subs({x: 0}) /
factorial(i) * x ** i for i in range(n)]).doit()
r = 2 ** n / factorial(n)
for o in [g, r]:
pprint(o)
print()
if not is_a and 9 * r <= 10 ** -4:
print(f'(a)')
print(f'n = {n}')
fa = g
is_a = True
if 9 * r <= 10 ** -6:
print(f'(b)')
print(f'n = {n}')
fb = g
break

diff = 10 ** -4
p = plot(f, fa, fb, exp(2),
(x, 2 - diff, 2 + diff),
ylim=(float(exp(2)) - diff, float(exp(2)) + diff),
show=False, legend=False)
colors = ['red', 'green', 'blue', 'brown']

for s, color in zip(p, colors):
s.line_color = color

p.show()
p.save('sample9.png')


C:\Users\...>py sample9.py
9.
1

2

x + 1

2

2
x
── + x + 1
2

4/3

3    2
x    x
── + ── + x + 1
6    2

2/3

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

4/15

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

4/45

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

8/315

7      6     5    4    3    2
x      x     x    x    x    x
──── + ─── + ─── + ── + ── + ── + x + 1
5040   720   120   24   6    2

2/315

8      7      6     5    4    3    2
x      x      x     x    x    x    x
───── + ──── + ─── + ─── + ── + ── + ── + x + 1
40320   5040   720   120   24   6    2

4/2835

9        8      7      6     5    4    3    2
x        x      x      x     x    x    x    x
────── + ───── + ──── + ─── + ─── + ── + ── + ── + x + 1
362880   40320   5040   720   120   24   6    2

4/14175

10        9        8      7      6     5    4    3    2
x         x        x      x      x     x    x    x    x
─────── + ────── + ───── + ──── + ─── + ─── + ── + ── + ── + x + 1
3628800   362880   40320   5040   720   120   24   6    2

8/155925

11         10        9        8      7      6     5    4    3    2
x          x         x        x      x      x     x    x    x    x
──────── + ─────── + ────── + ───── + ──── + ─── + ─── + ── + ── + ── + x + 1
39916800   3628800   362880   40320   5040   720   120   24   6    2

4/467775

(a)
n = 12
12         11         10        9        8      7      6     5    4    3
x          x          x         x        x      x      x     x    x    x
───────── + ──────── + ─────── + ────── + ───── + ──── + ─── + ─── + ── + ── +
479001600   39916800   3628800   362880   40320   5040   720   120   24   6

2
x
── + x + 1
2

8/6081075

13           12         11         10        9        8      7      6
x            x          x          x         x        x      x      x     x
────────── + ───────── + ──────── + ─────── + ────── + ───── + ──── + ─── + ──
6227020800   479001600   39916800   3628800   362880   40320   5040   720   12

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

8/42567525

14           13           12         11         10        9        8
x            x            x          x          x         x        x
─────────── + ────────── + ───────── + ──────── + ─────── + ────── + ───── + ─
87178291200   6227020800   479001600   39916800   3628800   362880   40320   5

7      6     5    4    3    2
x      x     x    x    x    x
─── + ─── + ─── + ── + ── + ── + x + 1
040   720   120   24   6    2

16
─────────
638512875

(b)
n = 15

C:\Users\...>