## 2019年12月30日月曜日

### 数学 - Python - 解析学 - 積分の計算 - 不定積分の計算 - 置換積分法、三角関数(正弦と余弦と正接)、有理関数の積分、部分分数分解、対数関数

1. $\begin{array}{l}\mathrm{sin}x\\ =\mathrm{sin}\left(\frac{x}{2}+\frac{x}{2}\right)\\ =2\mathrm{sin}\frac{x}{2}\mathrm{cos}\frac{x}{2}\\ =\frac{2\mathrm{sin}\frac{x}{2}\mathrm{cos}\frac{x}{2}}{{\mathrm{sin}}^{2}\frac{x}{2}+{\mathrm{cos}}^{2}\frac{x}{2}}\\ =\frac{2\frac{\mathrm{sin}\frac{x}{2}}{\mathrm{cos}\frac{x}{2}}}{\frac{{\mathrm{sin}}^{2}\frac{x}{2}}{{\mathrm{cos}}^{2}\frac{x}{2}}+1}\\ =\frac{2t}{1+{t}^{2}}\\ \mathrm{cos}x\\ =\mathrm{cos}\left(\frac{x}{2}+\frac{x}{2}\right)\\ ={\mathrm{cos}}^{2}\frac{x}{2}-{\mathrm{sin}}^{2}\frac{x}{2}\\ =\frac{{\mathrm{cos}}^{2}\frac{x}{2}-{\mathrm{sin}}^{2}\frac{x}{2}}{{\mathrm{cos}}^{2}\frac{x}{2}+{\mathrm{sin}}^{2}\frac{x}{2}}\\ =\frac{1-{t}^{2}}{1+{t}^{2}}\\ \frac{\mathrm{dt}}{\mathrm{dx}}=\frac{1}{{\mathrm{cos}}^{2}\frac{x}{2}}·\frac{1}{2}\\ =\frac{{\mathrm{cos}}^{2}\frac{x}{2}+{\mathrm{sin}}^{2}\frac{x}{2}}{2{\mathrm{cos}}^{2}\frac{x}{2}}\\ =\frac{1+{t}^{2}}{2}\\ \frac{\mathrm{dy}}{\mathrm{dt}}=\frac{2}{1+{t}^{2}}\end{array}$

よって、

$\begin{array}{l}\int \frac{\mathrm{dx}}{1+\mathrm{cos}x}\\ =\int \frac{1}{1+\frac{1-{t}^{2}}{1+{t}^{2}}}·\frac{2}{1+{t}^{2}}\mathrm{dt}\\ =\int \frac{2}{1+{t}^{2}+1-{t}^{2}}\mathrm{dt}\\ =\int \mathrm{dt}\\ =t\\ =\mathrm{tan}\frac{x}{2}\end{array}$

2. 置換積分と部分分数分解。

$\begin{array}{l}\int \frac{\mathrm{dx}}{\mathrm{cos}x}\\ =\int \frac{1+{t}^{2}}{1-{t}^{2}}·\frac{2}{1+{t}^{2}}\mathrm{dt}\\ =\int \frac{2}{1-{t}^{2}}\mathrm{dx}\\ =2\int \frac{1}{\left(1+t\right)\left(1-t\right)}\mathrm{dt}\\ \frac{A}{1+t}+\frac{B}{1-t}\\ =\frac{\left(B-A\right)t+\left(A+B\right)}{1-{t}^{2}}\\ -A+B=0\\ A+B=1\\ B=\frac{1}{2}\\ A=\frac{1}{2}\\ \int \frac{\mathrm{dx}}{\mathrm{cos}x}\\ =\int \frac{\mathrm{dt}}{1+t}+\int \frac{\mathrm{dt}}{1-t}\\ =\mathrm{log}\left|1+t\right|-\mathrm{log}\left|1-t\right|\\ =\mathrm{log}\left|\frac{1+t}{1-t}\right|\\ =\mathrm{log}\left|\frac{1+\mathrm{tan}\frac{x}{2}}{1-\mathrm{tan}\frac{x}{2}}\right|\end{array}$

3. $\begin{array}{l}\int \frac{\mathrm{sin}x}{1+\mathrm{sin}x}\mathrm{dx}\\ =\int \frac{2t}{1+{t}^{2}}·\frac{1}{1+\frac{2t}{1+{t}^{2}}}·\frac{2}{1+{t}^{2}}\mathrm{dt}\\ =\int \frac{4t}{\left(1+{t}^{2}\right)\left({t}^{2}+2t+1\right)}\mathrm{dt}\\ =4\int \frac{t}{\left(1+{t}^{2}\right){\left(1+t\right)}^{2}}\mathrm{dt}\\ \frac{At+B}{{t}^{2}+1}+\frac{C}{t+1}+\frac{D}{{\left(t+1\right)}^{2}}\\ \left(At+B\right){\left(t+1\right)}^{2}+C\left({t}^{2}+1\right)\left(t+1\right)+D\left({t}^{2}+1\right)\\ =\left(At+B\right)\left({t}^{2}+2t+1\right)+C\left({t}^{3}+{t}^{2}+t+1\right)+D\left({t}^{2}+1\right)\\ =\left(A+C\right){t}^{3}+\left(2A+B+C+D\right){t}^{2}+\left(A+2B+C\right)t+\left(B+C+D\right)\\ \left\{\begin{array}{l}A+C=0\\ 2A+B+C+D=0\\ A+2B+C=1\\ B+C+D=0\end{array}\\ C=-A\\ 2B=1\\ B=\frac{1}{2}\\ \frac{1}{2}-A+D=0\\ D=A-\frac{1}{2}\\ A+\frac{1}{2}+A-\frac{1}{2}=0\\ A=0\\ C=0\\ D=-\frac{1}{2}\\ \int \frac{t}{\left(1+{t}^{2}\right){\left(1+t\right)}^{2}}\mathrm{dt}\\ =\frac{1}{2}\left(\int \frac{\mathrm{dt}}{1+{t}^{2}}-\int \frac{\mathrm{dt}}{{\left(1+t\right)}^{2}}\right)\\ =\frac{1}{2}\left(\mathrm{arctan}t+\frac{1}{1+t}\right)\\ =\frac{1}{2}\left(\mathrm{arctan}\left(\mathrm{tan}\frac{x}{2}\right)+\frac{1}{1+\mathrm{tan}\frac{x}{2}}\right)\\ =\frac{1}{2}\left(\frac{x}{2}+\frac{1}{1+\mathrm{tan}\frac{x}{2}}\right)\\ \int \frac{\mathrm{sin}x}{1+\mathrm{sin}x}\mathrm{dx}\\ =2\left(\frac{x}{2}+\frac{1}{1+\mathrm{tan}\frac{x}{2}}\right)\\ =x+\frac{2}{1+\mathrm{tan}\frac{x}{2}}\end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import pprint, symbols, Derivative, sin, cos, tan, atan, log, plot

print('7.')

x = symbols('x')
fs = [1 / (1 + cos(x)),
1 / cos(x),
sin(x) / (1 + sin(x))]
gs = [tan(x / 2),
log(abs((1 + tan(x / 2)) / (1 - tan(x / 2)))),
x + 2 / (1 + tan(x / 2))]

s = {x: 1}

class MyTestCase(TestCase):
def test1(self):
self.assertEqual(float(fs[0].subs(s)),
float(Derivative(gs[0], x, 1).doit().subs(s)))

def test2(self):
self.assertEqual(float(fs[1].subs(s)),
float(Derivative(log((1 + tan(x / 2)) /
(1 - tan(x / 2))), x, 1).doit().subs(s)))

def test3(self):
self.assertEqual(float(fs[2].subs(s)),
float(Derivative(gs[2], x, 1).doit().subs(s)))

p = plot(*[f for f in fs + gs],
(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('sample7.png')

if __name__ == '__main__':
main()


% ./sample7.py -v
7.
test1 (__main__.MyTestCase) ... ok
test2 (__main__.MyTestCase) ... ok
test3 (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.044s

OK
%