## 2019年3月30日土曜日

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

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

コード

Python 3

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

print('2.')

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: Rational(1, 2)})
for o in [f, g, g.doit(), diff, float(diff), diff < Rational(1, 24)]:
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('sample2.png')


C:\Users\...>py -3 sample2.py
2.
x
ℯ

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

2
x
── + x + 1
2

13    1/2
- ── + ℯ
8

0.023721270700128146

True

C:\Users\...>