## 2019年6月4日火曜日

### 数学 - Python - 解析学 - 級数 - テイラーの公式 - テイラー多項式 - 指数関数、和、逆数、微分

1. $\begin{array}{l}\frac{d}{\mathrm{dx}}\frac{1}{{e}^{x}+{e}^{-x}}\\ =\frac{-\left({e}^{x}-{e}^{-x}\right)}{{\left({e}^{x}+{e}^{-x}\right)}^{2}}\\ =\frac{-{e}^{x}+{e}^{-x}}{{\left({e}^{x}+{e}^{-x}\right)}^{2}}\\ \frac{{d}^{2}}{d{x}^{2}}\frac{1}{{e}^{x}+{e}^{-x}}\\ =\frac{\left(-{e}^{x}-{e}^{-x}\right){\left({e}^{x}+{e}^{-x}\right)}^{2}}{{\left({e}^{x}+{e}^{-x}\right)}^{4}}\\ -\frac{\left(-{e}^{x}+{e}^{-x}\right)2\left({e}^{x}+{e}^{-x}\right)\left({e}^{x}-{e}^{-x}\right)}{{\left({e}^{x}+{e}^{-x}\right)}^{4}}\\ =\frac{\left(-{e}^{x}-{e}^{-x}\right)\left({e}^{x}+{e}^{-x}\right)-2\left(-{e}^{x}+{e}^{-x}\right)\left({e}^{x}-{e}^{-x}\right)}{{\left({e}^{x}+{e}^{-x}\right)}^{3}}\\ =\frac{-{e}^{2x}-1-1-{e}^{-2x}-2\left(-{e}^{2x}+1+1-{e}^{-2x}\right)}{{\left({e}^{x}+{e}^{-x}\right)}^{3}}\\ =\frac{{e}^{2x}+{e}^{-2x}-6}{{\left({e}^{x}+{e}^{-x}\right)}^{3}}\\ \frac{{d}^{3}}{d{x}^{3}}\frac{1}{{e}^{x}+{e}^{-x}}\\ =\frac{\left(2{e}^{2x}-2{e}^{-2x}\right){\left({e}^{x}+{e}^{-x}\right)}^{3}}{{\left({e}^{x}+{e}^{-x}\right)}^{6}}\\ -\frac{\left({e}^{2x}+{e}^{-2x}-6\right)3{\left({e}^{x}+{e}^{-x}\right)}^{2}\left({e}^{x}-{e}^{-x}\right)}{{\left({e}^{x}+{e}^{-x}\right)}^{6}}\end{array}$

よって、求める 問題の関数に対する3次のテイラー多項式は、

$\begin{array}{l}\frac{1}{2}+\frac{1}{2!}·\left(-\frac{1}{2}\right){x}^{2}\\ =\frac{1}{2}-\frac{1}{4}{x}^{2}\end{array}$

コード

Python 3

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

print('13.')

x = symbols('x')

f = 1 / (exp(x) + exp(-x))
g = sum([Derivative(f, x, n).doit().subs({x: 0}) / factorial(n) * x ** n
for n in range(4)])

pprint(g)

p = plot(exp(x), exp(-x), exp(x) + exp(-x), f, g.doit(),
(x, -5, 5),
ylim=(-5, 5),
legend=True,
show=False)
colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']

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

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


C:\Users\...>py sample13.py
13.
2
1   x
─ - ──
2   4

C:\Users\...>