## 2019年5月26日日曜日

### 数学 - Python - 解析学 - 級数 - テイラーの公式 - テイラー多項式 - 三角関数(正弦、余弦)、加法定理、2倍角

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

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

$\begin{array}{l}1+\frac{2}{2!}{x}^{2}\\ =1+{x}^{2}\end{array}$

コード

Python 3

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

print('4.')

x = symbols('x')

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

pprint(g)

p = plot(sin(x), cos(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('sample4.png')


C:\Users\...>py sample4.py
4.
3
2⋅x
- ──── + x
3

C:\Users\...>