前提・実現したいこと
Pythonで行列式=0となるような変数の代入値を求めるようなプログラムを作成しています.
下記作成中コードにて,「det A=0となるようなomegaの値を求める」コードを書きたいのですが,行列内に変数を含む場合のコーディングが分からないため,アドバイス頂けないでしょうか.
作成中のコード
Python
1import cmath 2import numpy as np 3import scipy 4from scipy.integrate import quad 5 6#数値は仮 7r0 = 1 8r1 = 1 9r2 = 1 10r3 = 1 11vr2 = 1 12beta2 = 1 13n = 1 14Q = 1 15 16ganma = - Q / cmath.tan(beta2) 17 18#積分1 19def M(func, a, b, **kwargs): 20 def real_func(r): 21 return scipy.real(func(r)) 22 def imag_func(r): 23 return scipy.imag(func(r)) 24 real_integral = quad(real_func, a, b, **kwargs) 25 imag_integral = quad(imag_func, a, b, **kwargs) 26 return (real_integral[0] + 1j*imag_integral[0], real_integral[1:], imag_integral[1:]) 27 28A_M = M(lambda r: r2 / (r * cmath.sin(beta2)), r2, r1) 29 30#複素積分計算1 31def F_r2(func, a, b, **kwargs): 32 def real_func(r): 33 return scipy.real(func(r)) 34 def imag_func(r): 35 return scipy.imag(func(r)) 36 real_integral = quad(real_func, a, b, **kwargs) 37 imag_integral = quad(imag_func, a, b, **kwargs) 38 return (real_integral[0] + 1j*imag_integral[0], real_integral[1:], imag_integral[1:]) 39 40A_F_r2 = F_r2(lambda r: cmath.exp((-1j* (omega * cmath.pi * (r**2 - r2**2) / Q - n * ganma * cmath.log(r / r2) / Q ))) * (r / r2)**(n + 1), r3, r2) 41 42#複素積分計算2 43def F_r3(func, a, b, **kwargs): 44 def real_func(r): 45 return scipy.real(func(r)) 46 def imag_func(r): 47 return scipy.imag(func(r)) 48 real_integral = quad(real_func, a, b, **kwargs) 49 imag_integral = quad(imag_func, a, b, **kwargs) 50 return (real_integral[0] + 1j*imag_integral[0], real_integral[1:], imag_integral[1:]) 51 52A_F_r3 = F_r3(lambda r: cmath.exp((-1j* (omega * cmath.pi * (r**2 - r2**2) / Q - n * ganma * cmath.log(r / r2) / Q ))) * (r / r3)**(n + 1), r3, r3) 53 54#複素積分計算3 55def G_r2(func, a, b, **kwargs): 56 def real_func(r): 57 return scipy.real(func(r)) 58 def imag_func(r): 59 return scipy.imag(func(r)) 60 real_integral = quad(real_func, a, b, **kwargs) 61 imag_integral = quad(imag_func, a, b, **kwargs) 62 return (real_integral[0] + 1j*imag_integral[0], real_integral[1:], imag_integral[1:]) 63 64A_G_r2 = G_r2(lambda r: cmath.exp((-1j* (omega * cmath.pi * (r**2 - r2**2) / Q - n * ganma * cmath.log(r / r2) / Q ))) * (r2 / r)**(n - 1), r2, r2) 65 66#複素積分計算4 67def G_r3(func, a, b, **kwargs): 68 def real_func(r): 69 return scipy.real(func(r)) 70 def imag_func(r): 71 return scipy.imag(func(r)) 72 real_integral = quad(real_func, a, b, **kwargs) 73 imag_integral = quad(imag_func, a, b, **kwargs) 74 return (real_integral[0] + 1j*imag_integral[0], real_integral[1:], imag_integral[1:]) 75 76A_G_r3 = G_r3(lambda r: cmath.exp((-1j* (omega * cmath.pi * (r**2 - r2**2) / Q - n * ganma * cmath.log(r / r2) / Q ))) * (r3 / r)**(n - 1), r3, r2) 77 78#raund_theta算出 79raund_theta = cmath.exp(-1j *(omega * cmath.pi * (r3**2 - r2**2) / Q - n * ganma * cmath.log(r3 / r2) / Q)) - ((n - 1) / r3 ) * 0.5 * A_G_r3[0] 80 81#各種値計算 82a11 = r2 * vr2 83 84a12 = (1 - cmath.exp(-2* beta2 * 1j)) * ( 1j * r2 * omega / cmath.tan(beta2) - 0.5 * A_M[0] * n * omega ) 85 86a13 = r1**n * omega 87 88a14 = omega / r1**n 89 90a22 = 1 - cmath.exp(-2* 1j * beta2) 91 92a23 = r1**(n -1) 93 94a24 = 1 / r1**(n + 1) 95 96a31 = (1j * omega - ganma /(2 * cmath.pi * r3**2) * 1j * n + Q/(2 * cmath.pi * r3**2)) * (0.5 * A_F_r3[0] - 0.5 * A_G_r3[0] - 1j * (r2 / r3)**(n + 1) * cmath.exp(-2 * 1j * beta2) * (-1j *((0.5 * A_F_r2[0]) + (0.5 * A_G_r2[0])))) + Q/(2 * cmath.pi * r3**2) * (raund_theta + 1j * (n + 1) * r2**(n + 1) / r3**(n + 2) * cmath.exp(-2 * 1j * beta2) * (-1j * ((0.5 * A_F_r2[0]) + (0.5 * A_G_r2[0])))) 97 98a32 = (1j * omega - ganma /(2 * cmath.pi * r3**2) * 1j * n + Q/(2 * cmath.pi * r3**2)) * (-1j * (r3 / r2)**(n - 1) - 1j * (r2 / r3)**(n + 1) * cmath.exp(-2 * 1j * beta2)) + (Q/(2 * cmath.pi * r3)) * (-1j * (n - 1) * r3**(n - 2) / r2**(n - 1) + 1j * (n + 1) * r2**(n + 1) / r3**(n + 2) * cmath.exp(-2 * 1j * beta2)) 99 100a43 = omega * r0**(n - 1) 101 102a44 = -omega / r0**(n + 1) 103 104#行列計算 105A = np.matrix([ 106[a11, a12, a13, a14], 107[0, a22, a23, a24], 108[a31, a32, 0, 0], 109[0, 0, a43, a44] 110])
omega=0じゃダメですか?
回答2件
あなたの回答
tips
プレビュー