## 2019年12月27日金曜日

### 数学 - Python - 解析学 - 積分の計算 - 不定積分の計算 - 漸化式による計算、三角関数(正弦と余弦、正接)、累乗、対数関数

1. 以下積分定数は省略。

$\begin{array}{l}\int {\mathrm{tan}}^{3}x\mathrm{dx}\\ =\int \frac{{\mathrm{sin}}^{3}x}{{\mathrm{cos}}^{3}x}\mathrm{dx}\\ =\int {\mathrm{sin}}^{3}x{\mathrm{cos}}^{-3}x\mathrm{dx}\\ =I\left(3,-3\right)\\ =-\frac{{\mathrm{sin}}^{4}x{\mathrm{cos}}^{-2}x}{-2}+\frac{2}{-2}I\left(3,-1\right)\\ =\frac{{\mathrm{sin}}^{4}x}{2{\mathrm{cos}}^{2}x}-\left(-\frac{{\mathrm{sin}}^{2}x}{2}+\frac{2}{2}I\left(1,-1\right)\right)\\ =\frac{{\mathrm{sin}}^{4}x}{2{\mathrm{cos}}^{2}x}+\frac{{\mathrm{sin}}^{2}x}{2}-\int \mathrm{sin}x{\mathrm{cos}}^{-1}x\mathrm{dx}\\ =\frac{{\mathrm{sin}}^{4}x}{2{\mathrm{cos}}^{2}x}+\frac{{\mathrm{sin}}^{2}x}{2}+\mathrm{log}\left|\mathrm{cos}x\right|\\ =\frac{{\mathrm{sin}}^{2}x\left({\mathrm{sin}}^{2}x+{\mathrm{cos}}^{2}x\right)}{2{\mathrm{cos}}^{2}x}+\mathrm{log}\left|\mathrm{cos}x\right|\\ =\frac{{\mathrm{tan}}^{2}x}{2}+\mathrm{log}\left|\mathrm{cos}x\right|\end{array}$

2. $\begin{array}{l}\int {\mathrm{sin}}^{2}x{\mathrm{cos}}^{2}x\mathrm{dx}\\ =\frac{{\mathrm{sin}}^{3}x\mathrm{cos}x}{4}+\frac{1}{4}I\left(2,0\right)\\ =\frac{{\mathrm{sin}}^{3}x\mathrm{cos}x}{4}+\frac{1}{4}\int {\mathrm{sin}}^{2}x{\mathrm{cos}}^{0}x\mathrm{dx}\\ =\frac{{\mathrm{sin}}^{3}x\mathrm{cos}x}{4}+\frac{1}{4}\left(-\frac{\mathrm{sin}x\mathrm{cos}x}{2}+\frac{1}{2}\int {\mathrm{sin}}^{0}x{\mathrm{cos}}^{0}xd\right)\\ =\frac{{\mathrm{sin}}^{3}x\mathrm{cos}x}{4}-\frac{\mathrm{sin}x\mathrm{cos}x}{8}+\frac{1}{8}x\\ =\frac{1}{8}\left(\mathrm{sin}x\mathrm{cos}x\left(2{\mathrm{sin}}^{2}x-1\right)+x\right)\\ =\frac{1}{8}\left(\mathrm{sin}x\mathrm{cos}x\left(\mathrm{cos}0-\mathrm{cos}2x-1\right)+x\right)\\ =\frac{1}{8}\left(x-\mathrm{sin}x\mathrm{cos}x\mathrm{cos}2x\right)\end{array}$

3. $\begin{array}{l}\int \frac{\mathrm{dx}}{{\mathrm{sin}}^{3}x{\mathrm{cos}}^{3}x}\\ =I\left(-3,-3\right)\\ =-\frac{{\mathrm{sin}}^{-2}x{\mathrm{cos}}^{-2}x}{-2}+\frac{-6+2}{-2}I\left(-3,-1\right)\\ =\frac{{\mathrm{sin}}^{-2}x{\mathrm{cos}}^{-2}x}{2}+2\left(\frac{{\mathrm{sin}}^{-2}x{\mathrm{cos}}^{0}x}{-2}+\frac{-2}{-2}I\left(-1,-1\right)\right)\\ =\frac{{\mathrm{sin}}^{-2}x{\mathrm{cos}}^{-2}x}{2}-{\mathrm{sin}}^{-2}x+2\int \frac{1}{\mathrm{sin}x\mathrm{cos}x}\mathrm{dx}\\ =\frac{{\mathrm{sin}}^{-2}x{\mathrm{cos}}^{-2}x}{2}-{\mathrm{sin}}^{-2}x+2\mathrm{log}\left|\mathrm{tan}x\right|\\ =\frac{1}{2{\mathrm{sin}}^{2}x{\mathrm{cos}}^{2}x}-\frac{1}{{\mathrm{sin}}^{2}x}+2\mathrm{log}\left|\mathrm{tan}x\right|\end{array}$

コード

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

print('5.')

x = symbols('x')
m, n = symbols('m, n', integer=True)
fs = [tan(x) ** 3, sin(x) ** 2 * cos(x) ** 2, 1 / (sin(x) ** 3 * cos(x) ** 3)]
gs = [tan(x) ** 2 / 2 + log(abs(cos(x))),
(x - sin(x) * cos(x) * cos(2 * x)) / 8,
1 / (2 * sin(x) ** 2 * cos(x) ** 2) - 1 / sin(x) ** 2 + 2 * log(abs(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()

p = plot(*fs, *gs,
(x, -5, 5),
ylim=(-5, 5),
legend=False,
show=False)
colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']

for o, color in zip(p, colors):
o.line_color = color

for o in zip(fs + gs, colors):
pprint(o)

p.show()
p.save('sample5.png')


% ./sample5.py
5.
(1)
⌠
⎮    3
⎮ tan (x) dx
⌡

1
log(cos(x)) + ─────────
2
2⋅cos (x)

(2)
⌠
⎮ ⎛1   cos(4⋅x)⎞
⎮ ⎜─ - ────────⎟ dx
⎮ ⎝8      8    ⎠
⌡

x   sin(4⋅x)
─ - ────────
8      32

(3)
⌠
⎮        1
⎮ ─────────────── dx
⎮    3       3
⎮ sin (x)⋅cos (x)
⌡

⎛    2   ⎞      1              1
2⋅log(sin(x)) - log⎝-cos (x)⎠ + ─────── - ─────────────────
2           2       2
cos (x)   2⋅sin (x)⋅cos (x)

⎛   3        ⎞
⎝tan (x), red⎠
⎛   2       2          ⎞
⎝sin (x)⋅cos (x), green⎠
⎛       1             ⎞
⎜───────────────, blue⎟
⎜   3       3         ⎟
⎝sin (x)⋅cos (x)      ⎠
⎛                   2          ⎞
⎜                tan (x)       ⎟
⎜log(│cos(x)│) + ───────, brown⎟
⎝                   2          ⎠
⎛x   sin(x)⋅cos(x)⋅cos(2⋅x)        ⎞
⎜─ - ──────────────────────, orange⎟
⎝8             8                   ⎠
⎛                     1              1                ⎞
⎜2⋅log(│tan(x)│) - ─────── + ─────────────────, purple⎟
⎜                     2           2       2           ⎟
⎝                  sin (x)   2⋅sin (x)⋅cos (x)        ⎠
%