## 2019年12月29日日曜日

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

1. $\begin{array}{l}\int \frac{\mathrm{dx}}{{a}^{2}{\mathrm{cos}}^{2}x+{b}^{2}{\mathrm{sin}}^{2}x}\\ =\int \frac{\frac{1}{{\mathrm{cos}}^{2}x}}{{a}^{2}+{b}^{2}\frac{{\mathrm{sin}}^{2}x}{{\mathrm{cos}}^{2}x}}dx\end{array}$

置換積分法。

$t=\mathrm{tan}x$

とおくと、

$\begin{array}{l}\frac{\mathrm{dt}}{\mathrm{dx}}=\frac{1}{{\mathrm{cos}}^{2}x}\\ \int \frac{1}{{a}^{2}+{b}^{2}{t}^{2}}\mathrm{dt}\\ =\frac{1}{{a}^{2}}\int \frac{\mathrm{dt}}{1+{\left(\frac{b}{a}t\right)}^{2}}\\ =\frac{1}{{a}^{2}}·\frac{a}{b}\mathrm{arctan}\left(\frac{b}{a}t\right)\\ =\frac{1}{ab}\mathrm{arctan}\left(\frac{b}{a}\mathrm{tan}x\right)\end{array}$

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

コード

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

print('6.')

a, b = symbols('a, b', nonzero=True)
x = symbols('x')
fs = [1 / (a ** 2 * cos(x) ** 2 + b ** 2 * sin(x) ** 2),
1 / (a ** 2 * cos(x) ** 2 - b ** 2 * sin(x) ** 2)]
gs = [atan(b * tan(x) / a) / (a * b),
log(abs((a * cos(x) + b * sin(x)) / (a * cos(x) - b * sin(x)))) / (2 * a * b)]

d = {a: 1, b: 2, x: 1}

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

p = plot(*[f.subs({a: 1, b: 2}) 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('sample6.png')

if __name__ == '__main__':
main()


\% ./sample6.py -v
6.
test1 (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.025s

OK
%