## 2019年6月14日金曜日

### 数学 - Python - 解析学 - 級数 - テイラーの公式 - テイラー多項式 - 自然対数の底(ネイピア数、オイラー数)、累乗(べき乗、平方)、逆数、小数、近似

1. $\begin{array}{l}{e}^{x}=1+x+\frac{1}{2!}{x}^{2}+\dots \\ {e}^{-2}=1+\left(-2\right)+\frac{1}{2!}{\left(-2\right)}^{2}+\dots \\ \frac{1}{3!}{\left(-2\right)}^{3}=\frac{-1}{3}{\left(-2\right)}^{2}=-\frac{4}{3}\\ \frac{1}{4!}{\left(-2\right)}^{4}=\frac{2}{3}\\ \frac{1}{5!}{\left(-2\right)}^{5}=-\frac{4}{15}\\ \frac{1}{6!}{\left(-2\right)}^{6}=\frac{4}{45}\\ \frac{1}{7!}{\left(-2\right)}^{7}=-\frac{8}{315}\\ \frac{1}{8!}{\left(-2\right)}^{8}=\frac{2}{315}\\ \frac{1}{9!}{\left(-2\right)}^{9}=-\frac{4}{2835}\\ \frac{1}{10!}{\left(-2\right)}^{10}=\frac{4}{14175}<1{0}^{-4}\end{array}$

よって、 求める値は、

$1-2+2-\frac{4}{3}+\frac{2}{3}-\frac{4}{15}+\frac{4}{45}-\frac{8}{315}+\frac{2}{315}-\frac{4}{2835}$

コード

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, plot, factorial, exp, summation
import matplotlib.pyplot as plt

print('17.')

k, n = symbols('k, n', integer=True)
f = summation(1 / factorial(k) * (-2) ** k, (k, 0, n))
for i in range(11):
a = f.subs({n: i})
for o in [a, float(a)]:
pprint(o)
print()

pprint(float(1 / exp(2)))

p = plot(1 / exp(2), *[f.subs({n: i}) for i in range(4, 10)],
legend=False,
show=False)
colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']

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

def f(n):
return sum([1 / factorial(n0) * (-2) ** n0 for n0 in range(n)])

ns = range(11)

plt.plot(ns, [1 / exp(2) for _ in ns], ns, [f(n) for n in ns])
plt.savefig('sample17.png')


C:\Users\...>py sample17.py
17.
-2   ⎛     2⎞  -2
ℯ   - ⎝1 - ℯ ⎠⋅ℯ

1.0

⎛     2⎞  -2    -2
- ⎝1 + ℯ ⎠⋅ℯ   + ℯ

-1.0

⎛       2⎞  -2
-2   ⎝2 - 2⋅ℯ ⎠⋅ℯ
ℯ   - ──────────────
2

1.0

⎛       2⎞  -2
⎝6 + 2⋅ℯ ⎠⋅ℯ      -2
- ────────────── + ℯ
6

-0.3333333333333333

⎛        2⎞  -2
-2   ⎝24 - 8⋅ℯ ⎠⋅ℯ
ℯ   - ───────────────
24

0.3333333333333333

⎛         2⎞  -2
⎝120 - 8⋅ℯ ⎠⋅ℯ      -2
- ──────────────── + ℯ
120

0.06666666666666667

⎛           2⎞  -2
⎝720 - 112⋅ℯ ⎠⋅ℯ      -2
- ────────────────── + ℯ
720

0.15555555555555556

⎛            2⎞  -2
⎝5040 - 656⋅ℯ ⎠⋅ℯ      -2
- ─────────────────── + ℯ
5040

0.13015873015873017

⎛              2⎞  -2
⎝40320 - 5504⋅ℯ ⎠⋅ℯ      -2
- ───────────────────── + ℯ
40320

0.13650793650793652

⎛                2⎞  -2
⎝362880 - 49024⋅ℯ ⎠⋅ℯ      -2
- ─────────────────────── + ℯ
362880

0.13509700176366843

⎛                  2⎞  -2
⎝3628800 - 491264⋅ℯ ⎠⋅ℯ      -2
- ───────────────────────── + ℯ
3628800

0.13537918871252205

0.1353352832366127

C:\Users\...>