## 2020年1月2日木曜日

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

1. $\begin{array}{l}\int {e}^{-x}{\mathrm{cos}}^{2}x\mathrm{dx}\\ =\int {e}^{-x}·\frac{\mathrm{cos}2x+1}{2}\mathrm{dx}\\ =\frac{1}{2}\int {e}^{-x}\mathrm{cos}2x\mathrm{dx}+\frac{1}{2}\int {e}^{-x}\mathrm{dx}\\ =\frac{1}{2}\int {e}^{-x}\mathrm{cos}2x\mathrm{dx}-\frac{1}{2}{e}^{-x}\\ \int {e}^{-x}\mathrm{cos}2x\mathrm{dx}\\ =-{e}^{-x}\mathrm{cos}2x-2\int {e}^{-x}\mathrm{sin}2x\mathrm{dx}\\ \int {e}^{-x}\mathrm{sin}2x\mathrm{dx}\\ =-{e}^{-x}\mathrm{sin}2x+2\int {e}^{-x}\mathrm{cos}2x\mathrm{dx}\\ \int {e}^{-x}\mathrm{cos}2x\mathrm{dx}\\ =-{e}^{-x}\mathrm{cos}2x+2{e}^{-x}\mathrm{sin}2x-4\int {e}^{-x}\mathrm{cos}2x\mathrm{dx}\\ \int {e}^{-x}\mathrm{cos}2x\mathrm{dx}=-\frac{1}{5}{e}^{-x}\mathrm{cos}2x+\frac{2}{5}{e}^{-x}\mathrm{sin}2x\\ \int {e}^{-x}{\mathrm{cos}}^{2}x\mathrm{dx}\\ =-\frac{1}{10}{e}^{-x}\mathrm{cos}2x+\frac{1}{5}{e}^{-x}\mathrm{sin}2x-\frac{1}{2}{e}^{-x}\end{array}$

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

3. $\alpha \ne -1$

の場合。

$\begin{array}{l}\int \frac{{\left(\mathrm{log}x\right)}^{\alpha }}{x}\mathrm{dx}\\ =\frac{1}{\alpha +1}·{\left(\mathrm{log}x\right)}^{\alpha +1}\end{array}$

である。

$\alpha =-1$

の場合。

$\begin{array}{l}\int \frac{{\left(\mathrm{log}x\right)}^{-1}}{x}\mathrm{dx}\\ =\int \frac{1}{x\mathrm{log}x}\mathrm{dx}\\ =\mathrm{log}\left|\mathrm{log}x\right|\end{array}$

4. $\begin{array}{l}\sqrt{{e}^{x}-1}=t\\ \frac{\mathrm{dt}}{\mathrm{dx}}=\frac{{e}^{x}}{2\sqrt{{e}^{x}-1}}\\ \int \sqrt{{e}^{x}-1}\mathrm{dx}\\ =\int \sqrt{{e}^{x}-1}·\frac{2\sqrt{{e}^{x}-1}}{{e}^{x}}\mathrm{dt}\\ =\int \frac{2{e}^{x}-2}{{e}^{x}}\mathrm{dt}\\ =2\left(\int \mathrm{dt}-\int \frac{1}{{e}^{x}}\mathrm{dt}\right)\\ =2\left(t-\int \frac{1}{1+{t}^{2}}\mathrm{dt}\right)\\ =2\left(\sqrt{{e}^{x}-1}-\mathrm{arctan}t\right)\\ =2\left(\sqrt{{e}^{x}-1}-\mathrm{arctan}\sqrt{{e}^{x}-1}\right)\end{array}$

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

6. $\begin{array}{l}\int \frac{1}{a+b\mathrm{tan}x}\mathrm{dx}\\ =\int \frac{\mathrm{cos}x}{a\left(\mathrm{cos}x\right)+b\mathrm{sin}x}\mathrm{dx}\\ \frac{d}{\mathrm{dx}}\left(a\left(\mathrm{cos}x\right)+b\mathrm{sin}x\right)\\ =-a\left(\mathrm{sin}x\right)+b\mathrm{cos}x\\ \mathrm{cos}x=A\left(a\left(\mathrm{cos}x\right)+b\mathrm{sin}x\right)+B\left(-a\left(\mathrm{sin}x\right)+b\mathrm{cos}x\right)\\ \left\{\begin{array}{l}aA+bB=1\\ bA-aB=0\end{array}\\ {a}^{2}A+abB=a\\ {b}^{2}A-abB=0\\ A=\frac{a}{{a}^{2}+{b}^{2}}\\ B=\frac{b}{a}A\\ =\frac{b}{{a}^{2}+{b}^{2}}\\ \int \frac{\mathrm{dx}}{a+b\mathrm{tan}x}\\ =\frac{a}{{a}^{2}+{b}^{2}}x+\frac{b}{{a}^{2}+{b}^{2}}\mathrm{log}\left|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, sin, cos, tan, atan, log, plot, Rational, exp, sqrt
from sympy import Integral, Derivative

print('8.')

x, alpha = symbols('x, alpha')
a, b = symbols('a, b', nonzero=True)
fs = [exp(-x) * cos(x) ** 2,
1 / (x ** 2 + 1) ** Rational(3, 2),
log(x) ** alpha / x,
sqrt(exp(x) - 1),
sin(log(x)),
1 / (a + b * tan(x))]

for i, f in enumerate(fs, 1):
print(f'({i})')
I = Integral(f, x)
for o in [I, I.doit()]:
pprint(o.simplify())
print()

class MyTestCase(TestCase):
def test(self):
gs = [-exp(-x) * cos(2 * x) / 10 + exp(-x) * sin(2 * x) / 5 - exp(-x) / 2,
sin(atan(x)),
2 * (sqrt(exp(x) - 1) - atan(sqrt(exp(x) - 1))),
x / 2 * (sin(log(x)) - cos(log(x)))]
for f, g in zip(fs[:2] + fs[3:-1], gs):
self.assertEqual(float(f.subs({x: 1})),
float(Derivative(g, x, 1).doit().subs({x: 1})))

p = plot(*[f.subs({a: 1, b: 2, alpha: 3}) for f in fs],
(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('sample8.png')

if __name__ == '__main__':
main()


% ./sample8.py -v
8.
(1)
⌠
⎮  -x    2
⎮ ℯ  ⋅cos (x) dx
⌡

⎛           cos(2⋅x)   5⎞  -x
⎜sin(2⋅x) - ──────── - ─⎟⋅ℯ
⎝              2       2⎠
─────────────────────────────
5

(2)
⌠
⎮      1
⎮ ─────────── dx
⎮         3/2
⎮ ⎛ 2    ⎞
⎮ ⎝x  + 1⎠
⌡

x
───────────
________
╱  2
╲╱  x  + 1

(3)
⌠
⎮    α
⎮ log (x)
⎮ ─────── dx
⎮    x
⌡

⎧   α + 1
⎪log     (x)
⎪───────────  for α ≠ -1
⎨   α + 1
⎪
⎪log(log(x))  otherwise
⎩

(4)
⌠
⎮    ________
⎮   ╱  x
⎮ ╲╱  ℯ  - 1  dx
⌡

________         ⎛   ________⎞
╱  x              ⎜  ╱  x     ⎟
2⋅╲╱  ℯ  - 1  - 2⋅atan⎝╲╱  ℯ  - 1 ⎠

(5)
⌠
⎮ sin(log(x)) dx
⌡

⎛         π⎞
-√2⋅x⋅cos⎜log(x) + ─⎟
⎝         4⎠
──────────────────────
2

(6)
⌠
⎮      1
⎮ ──────────── dx
⎮ a + b⋅tan(x)
⌡

⎛   1   ⎞
b⋅log⎜───────⎟
⎜   2   ⎟
⎛a         ⎞        ⎝cos (x)⎠
a⋅x + b⋅log⎜─ + tan(x)⎟ - ──────────────
⎝b         ⎠         2
────────────────────────────────────────
2    2
a  + b

test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.044s

OK
%