## 2019年6月1日土曜日

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

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

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

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

他の求め方。

$\begin{array}{l}\left(\mathrm{cos}x\right){e}^{x}\\ =\left(1-\frac{1}{2!}{x}^{2}\right)\left(1+x+\frac{1}{2}{x}^{2}+\frac{1}{6}{x}^{3}\right)+O\left({x}^{4}\right)\\ =1+x+\left(-\frac{1}{2}{x}^{3}+\frac{1}{6}{x}^{3}\right)+O\left({x}^{4}\right)\\ =1+x-\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, cos, exp

print('10.')

x = symbols('x')

f = cos(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(cos(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('sample10.png')


C:\Users\...>py sample10.py
10.
3
x
- ── + x + 1
3

C:\Users\...>