## 2020年1月11日土曜日

### 数学 - Python - 解析学 - 積分の計算 - 定積分の計算 - 三角関数(正弦と余弦)の積、加法定理、和、偶関数、奇関数

1. $\begin{array}{l}{\int }_{-\pi }^{\pi }\mathrm{sin}mx\mathrm{sin}nx\mathrm{dx}\\ ={\int }_{-\pi }^{\pi }\frac{\mathrm{cos}\left(m-n\right)x-\mathrm{cos}\left(m+n\right)x}{2}dx\\ m=n\ne 0\\ {\int }_{-\pi }^{\pi }\frac{1-\mathrm{cos}\left(m+n\right)x}{2}\mathrm{dx}\\ ={\int }_{0}^{\pi }\left(1-\mathrm{cos}\left(m+n\right)x\right)\mathrm{dx}\\ ={\left[x-\frac{\mathrm{sin}\left(m+n\right)x}{m+n}\right]}_{0}^{\pi }\\ =\pi \\ m\ne n\\ {\left[\frac{\mathrm{sin}\left(m-n\right)x}{m-n}-\frac{\mathrm{sin}\left(m+n\right)x}{m+n}\right]}_{0}^{\pi }\\ =0\end{array}$

2. $\begin{array}{l}{\int }_{-\pi }^{\pi }\mathrm{sin}mx\mathrm{cos}nx\mathrm{dx}\\ ={\int }_{-\pi }^{\pi }\frac{\mathrm{sin}\left(m+n\right)x+\mathrm{sin}\left(m-n\right)x}{2}\mathrm{dx}\\ =0\end{array}$

3. $\begin{array}{l}{\int }_{-\pi }^{\pi }\mathrm{cos}mx\mathrm{cos}nx\mathrm{dx}\\ ={\int }_{-\pi }^{\pi }\frac{\mathrm{cos}\left(m+n\right)x+\mathrm{cos}\left(m-n\right)x}{2}\mathrm{dx}\\ m=n\ne 0\\ {\int }_{0}^{\pi }\left(\mathrm{cos}\left(m+n\right)x+1\right)\mathrm{dx}\\ ={\left[\frac{\mathrm{sin}\left(m+n\right)x}{m+n}+x\right]}_{0}^{\pi }\\ =\pi \\ m\ne n\\ 0\\ m=n=0\\ {\int }_{-\pi }^{\pi }\mathrm{dx}=2\pi \end{array}$

コード

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

print('3.')

x = symbols('x')
m, n = symbols('m, n', integer=True, nonnegative=True)
fs = [sin(m * x) * sin(n * x),
sin(m * x) * cos(n * x),
cos(m * x) * cos(n * x)]

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

p = plot(*[f.subs({m: m0, n: n0})
for f in fs
for m0 in range(0, 2)
for n0 in range(0, 2)],
(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('sample3.png')


% ./sample3.py
3.
(1)
π
⌠
⎮  sin(m⋅x)⋅sin(n⋅x) dx
⌡
-π

⎧0   for (m = 0 ∧ n = 0) ∨ (m = 0 ∧ m = n ∧ n = 0) ∨ (m = 0 ∧ m = -n ∧ n = 0)
⎪
⎪-π   for (m = 0 ∧ m = -n) ∨ (m = -n ∧ m = n) ∨ (m = -n ∧ n = 0) ∨ (m = 0 ∧ m
⎨
⎪π                                          for (m = 0 ∧ m = n) ∨ (m = n ∧ n =
⎪
⎩0                                                            otherwise

∨ (m = 0 ∧ m = -n ∧ m = n ∧ n = 0) ∨ m = 0 ∨ n = 0

= -n ∧ m = n) ∨ (m = -n ∧ m = n ∧ n = 0) ∨ m = -n

0) ∨ m = n

(2)
π
⌠
⎮  sin(m⋅x)⋅cos(n⋅x) dx
⌡
-π

0

(3)
π
⌠
⎮  cos(m⋅x)⋅cos(n⋅x) dx
⌡
-π

⎧2⋅π                               for (m = 0 ∧ n = 0) ∨ (m = 0 ∧ m = n ∧ n =
⎪
⎨ π   for (m = 0 ∧ m = -n) ∨ (m = 0 ∧ m = n) ∨ (m = -n ∧ m = n) ∨ (m = n ∧ n =
⎪
⎩ 0

0) ∨ (m = 0 ∧ m = -n ∧ n = 0) ∨ (m = 0 ∧ m = -n ∧ m = n ∧ n = 0)

0) ∨ (m = -n ∧ n = 0) ∨ (m = 0 ∧ m = -n ∧ m = n) ∨ (m = -n ∧ m = n ∧ n = 0) ∨

otherwise

m = -n ∨ m = n

%