## 2019年5月28日火曜日

### 数学 - Python - 解析学 - 級数 - テイラーの公式 - テイラー多項式 - 三角関数(正接、正弦、余弦)、累乗(べき乗、平方)

1. $\begin{array}{l}{\mathrm{tan}}^{2}x\\ =\frac{{\mathrm{sin}}^{2}x}{{\mathrm{cos}}^{2}x}\\ =\frac{1-{\mathrm{cos}}^{2}x}{{\mathrm{cos}}^{2}x}\\ =\frac{1}{{\mathrm{cos}}^{2}x}-1\\ \frac{d}{\mathrm{dx}}{\mathrm{tan}}^{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}}{{\mathrm{dx}}^{2}}{\mathrm{tan}}^{2}x\\ =\frac{2{\mathrm{cos}}^{4}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}}^{2}x}+\frac{6{\mathrm{sin}}^{2}x}{{\mathrm{cos}}^{4}x}\\ =\frac{2}{{\mathrm{cos}}^{2}x}+\frac{6\left(1-{\mathrm{cos}}^{2}x\right)}{{\mathrm{cos}}^{4}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}}{\mathrm{tan}}^{2}x\\ =\frac{-24\left({\mathrm{cos}}^{3}x\right)\left(-\mathrm{sin}x\right)}{{\mathrm{cos}}^{8}x}-\frac{8\left(\mathrm{cos}x\right)\left(-\mathrm{sin}x\right)}{{\mathrm{cos}}^{4}x}\end{array}$

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

$\frac{2}{2!}{x}^{2}={x}^{2}$

コード

Python 3

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

print('6.')

x = symbols('x')

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

pprint(g)

p = plot(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('sample6.png')


C:\Users\...>py sample6.py
6.
2
x

C:\Users\...>