## 2019年5月23日木曜日

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

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

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

$\begin{array}{l}1-x+{x}^{2}+\frac{1}{3!}\left(1+2-8\right){x}^{3}\\ =1-x+{x}^{2}-\frac{5}{6}{x}^{3}\end{array}$

コード

Python 3

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

print('1.')

x = symbols('x')

f = 1 / (1 + sin(x))
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=(-10, 10),
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('sample1.png')


C:\Users\...>py sample1.py
1.
3
5⋅x     2
- ──── + x  - x + 1
6

C:\Users\...>