我正在尝试求解一组复数值的耦合常微分方程,然后绘制结果。我知道绘图应该是什么样子,一个 sin(x)^2 和一个 cos(x)^2 函数。但是,我绝对不明白。只是 1 和 0 处的水平线(我的初始条件)。这是氨脉泽的径向波近似的数值解。我尝试使用complex_ode,但是不断抛出参数错误,并且我找不到任何其他有用的资源。如有任何帮助,我们将不胜感激。
from scipy.integrate import odeint, complex_ode
## numerical solution from e NON-RWA
def odes1(x, t):
A = x[0]
B = x[1]
dgp_dt = (1/1j)*0.5 * B* (np.exp(-1j * t * (2*100)))
dgm_dt = (1/1j)*0.5 * A * (np.exp(1j * t * (2*100)))
return [dgp_dt, dgm_dt]
# intitial conditions
t0 = [0, 1]
# array of time values
k = np.linspace(0, 3*np.pi, 1000)
#solving the ODEs
sol1 = complex_ode(odes1, t0, k)
#plotting the solutions
plt.plot(k, np.real(sol1[:, 0]), label = r'$\gamma_{+}$'" No RWA", color = 'blue')
plt.plot(k, np.real(sol1[:, 1]), label = r'$\gamma_{-}$'" No RWA", color = 'red')
plt.legend()
plt.xlabel("Time ("r'$\frac{1}{\Omega_{0}}$'")")
plt.ylabel("Population")
plt.show()
我知道绘图应该是什么样子,一个 sin(x)^2 和一个 cos(x)^2 函数。但是,我绝对不明白。只是 1 和 0 处的水平线(我的初始条件)。该代码尝试绘制实部,但我也尝试按原样绘制,看起来 python 只是将复数值转换为实数。
当您使用
complex_ode
界面时,您负责集成。您还交换了方法签名中的 x
和 t
。
让我们重写你的问题:
import numpy as np
import matplotlib.pyplot as plt
from scipy import integrate
def system(t, x): # Mind the order of parameters
return np.array([
(1 / 1j) * 0.5 * x[1] * np.exp(-1j * t),
(1 / 1j) * 0.5 * x[0] * np.exp(+1j * t)
])
您的初始设置是:
x0 = [0, 1]
t = np.linspace(0, 3 * np.pi, 1000)
现在我们需要自己进行集成:
x = []
dt = t[1] - t[0]
while solver.successful() and solver.t < t.max() + dt:
solver.integrate(solver.t + dt)
x.append(solver.y)
x = np.array(x)
现在我们可以目视检查结果: