## 2019年4月1日月曜日

### 数学 - Python - 解析学 - 級数 - テイラーの公式 - 指数関数(誤差項の評価、3次まで、累乗根)

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

コード

Python 3

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

print('4.')

x = symbols('x')
f = exp(x)
g = sum([Derivative(f, x, i).subs({x: 0}) /
factorial(i) * x ** i for i in range(3)])
diff = (f - g.doit()).subs({x: 10 ** -2})
for o in [f, g, g.doit(), diff, float(diff), diff < Rational(1, 3) * 10 ** -6]:
pprint(o)
print()

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


C:\Users\...>py sample4.py
4.
x
ℯ

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

2
x
── + x + 1
2

1.67084167834730e-7

1.6708416783473012e-07

True

C:\Users\...>