## 2019年12月23日月曜日

### 数学 - Python - 解析学 - 積分の計算 - 不定積分の計算 - 有理関数の積分、部分分数分解、部分積分法

1. $\begin{array}{l}\frac{1}{{x}^{3}-x}\\ =\frac{1}{x\left({x}^{2}-1\right)}\\ =\frac{1}{x\left(x+1\right)\left(x-1\right)}\\ \frac{A}{x}+\frac{B}{x+1}+\frac{C}{x-1}\\ =\frac{A\left({x}^{2}-1\right)+B\left({x}^{2}-x\right)+C\left({x}^{2}+x\right)}{{x}^{3}-x}\\ =\frac{\left(A+B+C\right){x}^{2}+\left(-B+C\right)x-A}{{x}^{3}-x}\\ \left\{\begin{array}{l}A+B+C=0\\ -B+C=0\\ -A=1\end{array}\\ A=-1\\ B=C\\ -1+2B=0\\ B=\frac{1}{2}\end{array}$

よって 求める積分は、

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

（積分定数の記述は省略）

2. $\begin{array}{l}\frac{{x}^{3}}{{x}^{3}-7x+6}\\ =\frac{{x}^{3}-7x+6+7x-6}{{x}^{3}-7x+6}\\ =1+\frac{7x-6}{{x}^{3}-7x+6}\\ =1+\frac{7x-6}{\left(x-1\right)\left({x}^{2}+x-6\right)}\\ =1+\frac{7x-6}{\left(x-1\right)\left(x-2\right)\left(x+3\right)}\\ \frac{A}{x-1}+\frac{B}{x-2}+\frac{C}{x+3}\\ =\frac{A\left({x}^{2}+x-6\right)+B\left({x}^{2}+2x-3\right)+C\left({x}^{2}-3x+2\right)}{{x}^{2}-7x+6}\\ =\frac{\left(A+B+C\right){x}^{2}+\left(A+2B-3C\right)x+\left(-6A-3B+2C\right)}{{x}^{2}-7x+6}\\ \left\{\begin{array}{l}A+B+C=0\\ A+2B-3C=7\\ -6A-3B+2C=-6\end{array}\\ 4A+5B=7\\ -8A-5B=-6\\ -4A=1\\ A=-\frac{1}{4}\\ -1+5B=7\\ B=\frac{8}{5}\\ C=\frac{1}{4}-\frac{8}{5}=-\frac{27}{20}\end{array}$

よって、

$\begin{array}{l}\int \frac{{x}^{3}}{{x}^{3}-7x+6}\mathrm{dx}\\ =x-\frac{1}{4}\mathrm{log}\left|x-1\right|+\frac{8}{5}\mathrm{log}\left|x-2\right|-\frac{27}{20}\mathrm{log}\left|x+3\right|\end{array}$

3. $\begin{array}{l}\frac{1}{{x}^{4}-1}\\ =\frac{1}{\left({x}^{2}+1\right)\left(x+1\right)\left(x-1\right)}\\ \frac{Ax+B}{{x}^{2}+1}+\frac{C}{x+1}+\frac{D}{x-1}\\ =\frac{\left(Ax+B\right)\left({x}^{2}-1\right)+C\left({x}^{2}+1\right)\left(x-1\right)+D\left({x}^{2}+1\right)\left(x+1\right)}{{x}^{4}-1}\\ =\frac{A{x}^{3}-Ax+B{x}^{2}-B+C\left({x}^{3}-{x}^{2}+x-1\right)+D\left({x}^{3}+{x}^{2}+x+1\right)}{{x}^{4}-1}\\ =\frac{\left(A+C+D\right){x}^{3}+\left(B-C+D\right){x}^{2}+\left(-A+C+D\right)x+\left(-B-C+D\right)}{{x}^{4}-1}\\ \left\{\begin{array}{l}A+C+D=0\\ B-C+D=0\\ -A+C+D=0\\ -B-C+D=1\end{array}\\ A=0\\ 2B=-1\\ B=-\frac{1}{2}\\ D=-C\\ -\frac{1}{2}-C-C=0\\ C=-\frac{1}{4}\\ D=\frac{1}{4}\end{array}$

よって、

$\begin{array}{l}\int \frac{1}{{x}^{4}-1}\mathrm{dx}\\ =-\frac{1}{2}\mathrm{arctan}x-\frac{1}{4}\mathrm{log}\left|x+1\right|+\frac{1}{4}\mathrm{log}\left|x-1\right|\\ =-\frac{1}{2}\mathrm{arctan}x+\frac{1}{4}\mathrm{log}\left|\frac{x-1}{x+1}\right|\end{array}$

4. $\begin{array}{l}\frac{A}{x}+\frac{B}{x+1}+\frac{C}{{\left(x+1\right)}^{2}}+\frac{D}{{\left(x+1\right)}^{3}}\\ =\frac{A{\left(x+1\right)}^{3}+Bx{\left(x+1\right)}^{2}+Cx\left(x+1\right)+Dx}{x{\left(x+1\right)}^{3}}\\ =\frac{\left(A+B\right){x}^{3}+\left(3A+2B+C\right){x}^{2}+\left(3A+B+C+D\right)x+A}{x{\left(x+1\right)}^{3}}\\ A=-1\\ B=2\\ -3+4+C=0\\ C=-1\\ -3+2-1+D=0\\ D=2\end{array}$

よって、

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

5. $\begin{array}{l}\frac{1}{{x}^{3}+1}\\ =\frac{1}{\left(x+1\right)\left({x}^{2}-x+1\right)}\\ \frac{A}{x+1}+\frac{Bx+C}{{x}^{2}-x+1}\\ =\frac{A\left({x}^{2}-x+1\right)+\left(Bx+C\right)\left(x+1\right)}{{x}^{3}+1}\\ =\frac{\left(A+B\right){x}^{2}+\left(-A+B+C\right)x+\left(A+C\right)}{{x}^{3}+1}\\ \left\{\begin{array}{l}A+B=0\\ -A+B+C=0\\ A+C=1\end{array}\\ B=-A\\ C=1-A\\ -A-A+1-A=0\\ A=\frac{1}{3}\\ B=-\frac{1}{3}\\ C=\frac{2}{3}\end{array}$

よって、

$\begin{array}{l}\int \frac{1}{{x}^{3}+1}\mathrm{dx}\\ =\frac{1}{3}\mathrm{log}\left|x+1\right|-\frac{1}{3}\int \frac{x-2}{{x}^{2}-x+1}\mathrm{dx}\\ =\frac{1}{3}\mathrm{log}\left|x+1\right|-\frac{1}{3}·\frac{1}{2}\int \frac{2x-4}{{x}^{2}-x+1}\mathrm{dx}\\ =\frac{1}{3}\mathrm{log}\left|x+1\right|-\frac{1}{6}\int \frac{2x-1-3}{{x}^{2}-x+1}\mathrm{dx}\\ =\frac{1}{3}\mathrm{log}\left|x+1\right|-\frac{1}{6}\int \frac{2x-1}{{x}^{2}-x+1}\mathrm{dx}+\frac{1}{2}\int \frac{1}{{x}^{2}-x+1}\mathrm{dx}\\ =\frac{1}{3}\mathrm{log}\left|x+1\right|-\frac{1}{6}\mathrm{log}\left({x}^{2}-x+1\right)+\frac{1}{2}\int \frac{1}{{\left(x-\frac{1}{2}\right)}^{2}+{\left(\frac{\sqrt{3}}{2}\right)}^{2}}\mathrm{dx}\\ =\frac{1}{3}\mathrm{log}\left|x+1\right|-\frac{1}{6}\mathrm{log}\left({x}^{2}-x+1\right)+\frac{1}{2}·\frac{2}{\sqrt{3}}\mathrm{arctan}\left(\frac{2}{\sqrt{3}}\left(x-\frac{1}{2}\right)\right)\\ =\frac{1}{3}\mathrm{log}\left|x+1\right|-\frac{1}{6}\mathrm{log}\left({x}^{2}-x+1\right)+\frac{1}{\sqrt{3}}\mathrm{arctan}\frac{2x-1}{\sqrt{3}}\\ =\frac{1}{3}\mathrm{log}\frac{{\left(x+1\right)}^{2}}{{x}^{2}-x+1}+\frac{1}{\sqrt{3}}\mathrm{arctan}\frac{2x-1}{\sqrt{3}}\end{array}$

6. $\begin{array}{l}\int \frac{1}{{\left({x}^{3}+1\right)}^{2}}\mathrm{dx}\\ =\int \frac{\left({x}^{3}+1\right)-\frac{x}{3}·3{x}^{2}}{{\left({x}^{3}+1\right)}^{2}}\mathrm{dx}\\ =\int \frac{1}{{x}^{3}+1}dx-\frac{1}{3}\int \frac{x·3{x}^{2}}{{\left({x}^{3}+1\right)}^{2}}\mathrm{dx}\\ =\int \frac{1}{{x}^{3}+1}\mathrm{dx}+\frac{1}{3}\int \left(\frac{d}{\mathrm{dx}}\left(\frac{1}{{x}^{3}+1}\right)\right)x\mathrm{dx}\\ =\int \frac{1}{{x}^{3}+1}\mathrm{dx}+\frac{1}{3}·\frac{x}{{x}^{3}+1}-\frac{1}{3}\int \frac{1}{{x}^{3}+1}\mathrm{dx}\\ =\frac{2}{3}\int \frac{1}{{x}^{3}+1}\mathrm{dx}+\frac{x}{3\left({x}^{3}+1\right)}\\ =\frac{x}{3\left({x}^{2}+1\right)}+\frac{2}{9}\mathrm{log}\frac{{\left(x+1\right)}^{2}}{{x}^{2}-x+1}+\frac{2}{3\sqrt{3}}\mathrm{arctan}\frac{2x-1}{\sqrt{3}}\end{array}$

コード

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

print('1.')

x = symbols('x')
fs = [1 / (x ** 3 - x),
x ** 3 / (x ** 3 - 7 * x + 6),
1 / (x ** 4 - 1),
(x ** 3 - 1) / (x * (x + 1) ** 3),
1 / (x ** 3 + 1),
1 / (x ** 3 + 1) ** 2]

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,
(x, -5, 5),
ylim=(-5, 5),
show=False,
legend=True)
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('sample1.png')


% ./sample1.py
1.
(1)
⌠
⎮   1
⎮ ────── dx
⎮  3
⎮ x  - x
⌡

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

(2)
⌠
⎮       3
⎮      x
⎮ ──────────── dx
⎮  3
⎮ x  - 7⋅x + 6
⌡

8⋅log(x - 2)   log(x - 1)   27⋅log(x + 3)
x + ──────────── - ────────── - ─────────────
5             4              20

(3)
⌠
⎮   1
⎮ ────── dx
⎮  4
⎮ x  - 1
⌡

log(x - 1)   log(x + 1)   atan(x)
────────── - ────────── - ───────
4            4           2

(4)
⌠
⎮    3
⎮   x  - 1
⎮ ────────── dx
⎮          3
⎮ x⋅(x + 1)
⌡

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

(5)
⌠
⎮   1
⎮ ────── dx
⎮  3
⎮ x  + 1
⌡

⎛√3⋅(2⋅x - 1)⎞
⎛ 2        ⎞   √3⋅atan⎜────────────⎟
log(x + 1)   log⎝x  - x + 1⎠          ⎝     3      ⎠
────────── - ─────────────── + ─────────────────────
3               6                    3

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

⎛ 3    ⎞ ⎛                  ⎛ 2        ⎞            ⎛√3⋅(2⋅x - 1)⎞⎞
3⋅x + ⎝x  + 1⎠⋅⎜2⋅log(x + 1) - log⎝x  - x + 1⎠ + 2⋅√3⋅atan⎜────────────⎟⎟
⎝                                          ⎝     3      ⎠⎠
─────────────────────────────────────────────────────────────────────────
⎛ 3    ⎞
9⋅⎝x  + 1⎠

%