解决复杂耦合微分方程时的Python误差

时间:2016-01-06 07:15:43

标签: python numpy scipy ode

我正在尝试解决复杂耦合微分方程如下。

import numpy as np
from scipy.integrate import complex_ode

def cae(z, A, params):

    A1, A2, A3 = A
    alpha, gamma, dbeta = params

    dA = [
        -0.5*alpha*A1 + 1j*gamma*(np.abs(A1)**2 + 2*np.abs(A2)**2 + 2*np.abs(A3)**2)*A1 + 2j*gamma*A2*A3*np.conjugate(A1)*np.exp(1j*dbeta*z),
        -0.5*alpha*A2 + 1j*gamma*(2*np.abs(A1)**2 + np.abs(A2)**2 + 2*np.abs(A3)**2)*A2 + 1j*gamma*A1**2*np.conjugate(A3)*np.exp(-1j*dbeta*z),
        -0.5*alpha*A3 + 1j*gamma*(2*np.abs(A1)**2 + 2*np.abs(A2)**2 + np.abs(A3)**2)*A3 + 1j*gamma*A1**2*np.conjugate(A2)*np.exp(-1j*dbeta*z),
    ]

    return dA


A0 = [1, 1e-3, 0])
z0 = 0
params = [0, 2, 0]
L = 2.5
dz = 0.01


sol = complex_ode(cae).set_integrator("dopri5")
sol.set_initial_value(A0, z0).set_f_params(params)

while sol.successful() and sol.t < L:
    sol.integrate(sol.t+dz)

但是,此代码会出现以下错误。

File "C:\Python27\lib\site-packages\scipy\integrate\_ode.py", line 472, in _wrap
  f = self.cf(*((t, y[::2] + 1j * y[1::2]) + f_args))
TypeError: can't multiply sequence by non-int of type 'complex'

任何人都可以解释为什么会发生这种情况以及如何解决这个问题吗?

0 个答案:

没有答案