## 2019年3月16日土曜日

### 数学 - Python - 解析学 - 級数 - テイラーの公式 - 三角関数(正接、4次、多項式)

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

求める4次のテイラー多項式。

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

コード

Python 3

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

print('6.')

x = symbols('x')
f = tan(x)
g = sum([Derivative(f, x, i).subs({x: 0}) * x ** i / factorial(i)
for i in range(5)])

for o in [g, g.doit()]:
pprint(o)
print()

p = plot(tan(x), g.doit(), ylim=(-10, 10), show=False, legend=True)
colors = ['red', 'green', 'blue']
for o, color in zip(p, colors):
o.line_color = color

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


C:\Users\...>py -3 sample6.py
6.
⎛  4        ⎞│         ⎛  3        ⎞│         ⎛  2        ⎞│
4 ⎜ d         ⎟│       3 ⎜ d         ⎟│       2 ⎜ d         ⎟│
x ⋅⎜───(tan(x))⎟│      x ⋅⎜───(tan(x))⎟│      x ⋅⎜───(tan(x))⎟│
⎜  4        ⎟│         ⎜  3        ⎟│         ⎜  2        ⎟│
⎝dx         ⎠│x=0      ⎝dx         ⎠│x=0      ⎝dx         ⎠│x=0     ⎛d
──────────────────── + ──────────────────── + ──────────────────── + x⋅⎜──(tan
24                     6                      2               ⎝dx

⎞│
(x))⎟│
⎠│x=0

3
x
── + x
3

C:\Users\...>