2020年1月11日土曜日

学習環境

解析入門(上) (松坂和夫 数学入門シリーズ 4) (松坂 和夫(著)、岩波書店)の第8章(積分の計算)、8.2(定積分の計算)、問題3の解答を求めてみる。



    1. - π π sin m x sin n x dx = - π π cos m - n x - cos m + n x 2 d x m = n 0 - π π 1 - cos m + n x 2 dx = 0 π 1 - cos m + n x dx = x - sin m + n x m + n 0 π = π m n sin m - n x m - n - sin m + n x m + n 0 π = 0

    2. - π π sin m x cos n x dx = - π π sin m + n x + sin m - n x 2 dx = 0

    3. - π π cos m x cos n x dx = - π π cos m + n x + cos m - n x 2 dx m = n 0 0 π cos m + n x + 1 dx = sin m + n x m + n + x 0 π = π m n 0 m = n = 0 - π π dx = 2 π

コード

#!/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')

入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))

% ./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
               
               

%

0 コメント:

コメントを投稿