2019年3月22日金曜日

数学 - Python - 解析学 - 級数 - テイラーの公式 - 三角関数(余弦、逆数、積、積分、近似値(小数第3位まで))

1. $\begin{array}{}f\left(x\right)=\mathrm{cos}x-1\\ f\text{'}\left(x\right)=-\mathrm{sin}x\\ {f}^{\left(2\right)}\left(x\right)=-\mathrm{cos}x\end{array}$

よって、

$\begin{array}{}\mathrm{cos}x-1\\ =-\frac{1}{2!}{x}^{2}++{R}_{4}\left(x\right)\\ \left|{R}_{4}\right|\le 2·\frac{{\left|x\right|}^{4}}{4!}=\frac{{\left|x\right|}^{4}}{2·3!}\end{array}$

ゆえに、

$\begin{array}{}\frac{\mathrm{cos}x-1}{x}\\ =-\frac{1}{2}x+\frac{{R}_{4}\left(x\right)}{x}\\ \left|\frac{{R}_{4}\left(x\right)}{x}\right|\le \frac{{\left|x\right|}^{3}}{2·3!}\end{array}$

したがって、

$\begin{array}{}\underset{0}{\overset{0.1}{\int }}\frac{\mathrm{cos}x-1}{x}\mathrm{dx}\\ ={\left[-\frac{1}{4}{x}^{2}\right]}_{0}^{0.1}+\underset{0}{\overset{0.1}{\int }}\frac{{R}_{4}\left(x\right)}{x}\mathrm{dx}\end{array}$

かつ

$\begin{array}{}\underset{0}{\overset{0.1}{\int }}\left|\frac{{R}_{4}\left(x\right)}{x}\right|\mathrm{dx}\\ \le \underset{0}{\overset{0.1}{\int }}\frac{{x}^{3}}{2·3!}\mathrm{dx}\\ ={\left[\frac{{x}^{4}}{8·3!}\right]}_{0}^{0.1}\\ =\frac{1}{8·3!}1{0}^{-4}\end{array}$

よって求める積分の小数第3位までの値は、

$\begin{array}{}{\left[-\frac{1}{4}{x}^{2}\right]}_{0}^{0,1}\\ =-\frac{1}{4·1{0}^{2}}\\ =-\frac{1}{400}\\ =-0.0025\\ -0.002\end{array}$

コード

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, Rational, cos, Integral, plot

print('11-(b).')

x = symbols('x')
f = (cos(x) - 1) / x
i = Integral(f, (x, 0, Rational(1, 10)))

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

p = plot(cos(x), cos(x) - 1, x, f, show=False, legend=True)
colors = ['red', 'green', 'blue', 'brown']
for s, color in zip(p, colors):
s.line_color = color
p.show()
p.save('sample11.png')


C:\Users\...>py -3 sample11.py
11-(b).
1/10
⌠
⎮   cos(x) - 1
⎮   ────────── dx
⎮       x
⌡
0

log(100)
- ──────── + Ci(1/10) - γ + 2⋅log(10)
2

-0.0024989585647838155

C:\Users\...>