## 2020年1月16日木曜日

### 数学 - Python - 解析学 - 積分の計算 - 定積分の計算 - 部分積分法、累乗、指数関数、対数関数、積、漸化式、階乗

1. $\begin{array}{l}\int {x}^{2n+1}{e}^{-{x}^{2}}\mathrm{dx}\\ =\frac{{x}^{2\left(n+1\right)}}{2\left(n+1\right)}{e}^{-{x}^{2}}-\frac{1}{2\left(n+1\right)}\int {x}^{2\left(n+1\right)}{e}^{-{x}^{2}}\left(-2x\right)\mathrm{dx}\\ =\frac{{x}^{2\left(n+1\right)}}{2\left(n+1\right)}{e}^{-{x}^{2}}+\frac{1}{n+1}\int {x}^{2\left(n+1\right)+1}{e}^{-{x}^{2}}\mathrm{dx}\\ {\int }_{0}^{\infty }{x}^{2n+1}{e}^{-{x}^{2}}\mathrm{dx}=\frac{1}{n+1}{\int }_{0}^{\infty }{x}^{2\left(n+1\right)+1}{e}^{-{x}^{2}}\mathrm{dx}\\ {\int }_{0}^{\infty }{x}^{2\left(n+1\right)+1}{e}^{-{x}^{2}}\mathrm{dx}=\left(n+1\right){\int }_{0}^{\infty }{x}^{2n+1}{e}^{-{x}^{2}}\mathrm{dx}\\ {\int }_{0}^{\infty }x{e}^{-{x}^{2}}\mathrm{dx}\\ =\underset{b\to \infty }{\mathrm{lim}}{\int }_{0}^{b}x{e}^{-{x}^{2}}\mathrm{dx}\\ =-\frac{1}{2}\underset{b\to \infty }{\mathrm{lim}}{\left[{e}^{-{x}^{2}}\right]}_{0}^{b}\\ =-\frac{1}{2}\underset{b\to \infty }{\mathrm{lim}}\left({e}^{-{b}^{2}}-1\right)\\ =\frac{1}{2}\end{array}$

よって、

${\int }_{0}^{n}{x}^{2n+1}{e}^{-{x}^{2}}\mathrm{dx}=\frac{n!}{2}$

2. $\begin{array}{l}\int {x}^{\alpha }{\left(\mathrm{log}x\right)}^{n}\mathrm{dx}\\ =\frac{{x}^{\alpha +1}}{\alpha +1}{\left(\mathrm{log}x\right)}^{n}-\frac{1}{\alpha +1}\int {x}^{\alpha +1}n{\left(\mathrm{log}x\right)}^{n-1}·\frac{1}{x}\mathrm{dx}\\ =\frac{{x}^{\alpha +1}}{\alpha +1}{\left(\mathrm{log}x\right)}^{n}-\frac{n}{\alpha +1}\int {x}^{\alpha }{\left(\mathrm{log}x\right)}^{n-1}\mathrm{dx}\\ {\int }_{0}^{1}{x}^{\alpha }{\left(\mathrm{log}x\right)}^{n}\mathrm{dx}=-\frac{n}{\alpha +1}{\int }_{0}^{1}{x}^{\alpha }{\left(\mathrm{log}x\right)}^{n-1}\mathrm{dx}\\ {\int }_{0}^{1}{x}^{\alpha }\mathrm{log}x\mathrm{dx}\\ =-\frac{1}{\alpha +1}{\int }_{0}^{1}{x}^{\alpha }\mathrm{dx}\\ =-\frac{1}{{\left(\alpha +1\right)}^{2}}{\left[{x}^{\alpha +1}\right]}_{0}^{1}\\ =-\frac{1}{{\left(\alpha +1\right)}^{2}}\end{array}$

よって、

$\begin{array}{l}{\int }_{0}^{1}{x}^{\alpha }{\left(\mathrm{log}x\right)}^{n}\mathrm{dx}\\ ={\left(-1\right)}^{n}\frac{n!}{{\left(x+1\right)}^{2+n-1}}\\ ={\left(-1\right)}^{n}\frac{n!}{{\left(\alpha +1\right)}^{n+1}}\end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import pprint, symbols, Integral, log, exp, oo, Rational, plot

print('7.')

x = symbols('x', real=True)
n = symbols('n', integer=True, nonnegative=True)
f = x ** (2 * n + 1) * exp(-x ** 2)
a = 2
g1 = x ** -Rational(1, 2) * log(x) ** n
g2 = x ** 2 * log(x) ** n
xs = [(0, oo), (0, 1), (0, 1)]

for i, (h, (x1, x2)) in enumerate(zip([f, g1, g2], xs), 1):
print(f'({i})')
I = Integral(h, (x, x1, x2))
for o in [I, I.doit()]:
pprint(o.simplify())
print()

p = plot(*[h.subs({n: n0})
for h in [f, g1, g2]
for n0 in range(3)],
(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(p, colors):
pprint(o)
p.show()
p.save('sample7.png')


% ./sample7.py
7.
(1)
∞
⌠
⎮             2
⎮  2⋅n + 1  -x
⎮ x       ⋅ℯ    dx
⌡
0

n!
──
2

(2)
1
⌠
⎮    n
⎮ log (x)
⎮ ─────── dx
⎮    √x
⌡
0

1
⌠
⎮    n
⎮ log (x)
⎮ ─────── dx
⎮    √x
⌡
0

(3)
1
⌠
⎮  2    n
⎮ x ⋅log (x) dx
⌡
0

1
⌠
⎮  2    n
⎮ x ⋅log (x) dx
⌡
0

(cartesian line: x*exp(-x**2) for x over (-5.0, 5.0), red)
(cartesian line: x**3*exp(-x**2) for x over (-5.0, 5.0), green)
(cartesian line: x**5*exp(-x**2) for x over (-5.0, 5.0), blue)
(cartesian line: 1/sqrt(x) for x over (-5.0, 5.0), brown)
(cartesian line: log(x)/sqrt(x) for x over (-5.0, 5.0), orange)
(cartesian line: log(x)**2/sqrt(x) for x over (-5.0, 5.0), purple)
(cartesian line: x**2 for x over (-5.0, 5.0), pink)
(cartesian line: x**2*log(x) for x over (-5.0, 5.0), gray)
(cartesian line: x**2*log(x)**2 for x over (-5.0, 5.0), skyblue)
%