2019年5月31日金曜日

数学 - Python - 解析学 - 級数 - テイラーの公式 - テイラー多項式 - 三角関数(正弦、余弦)、指数関数、積、微分

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

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

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

他の求め方。

$\begin{array}{l}\mathrm{sin}x=x-\frac{1}{3!}{x}^{3}+\dots \\ {e}^{x}=1+x+\frac{1}{2!}{x}^{2}+\dots \\ \left(x-\frac{1}{6}{x}^{3}\right)\left(1+x+\frac{1}{2}{x}^{2}\right)\\ =x+{x}^{2}+\left(-\frac{1}{6}+\frac{1}{2}\right){x}^{3}+O\left({x}^{4}\right)\\ =x+{x}^{2}+\frac{1}{3}{x}^{3}+O\left({x}^{4}\right)\end{array}$

コード

Python 3

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

print('9.')

x = symbols('x')

f = sin(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(sin(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('sample9.png')


C:\Users\...>py sample9.py
9.
3
x     2
── + x  + x
3

C:\Users\...>