0

I'm trying to solve complex coupled differential equations as follows.

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)

But, this code gives the following error.

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'

Can anyone explain why this is happening and how to fix it?

  • The link I suggested for a duplicate is the answer to your problem. You get a different error compared to the other post because your parameters are an iterable, while the other one is a float. As the answer suggests, either use `ode()` with the `zvode` integrator, or `complex_ode()` with a wrapper function. Or you can use `complex_ode()` as is, but without setting the parameters, i.e., do not call `set_f_params()`). Just hardcode them in your function `cae()`, so that it effectively becomes `cae(z, A)`. – Reti43 Jan 07 '16 at 13:04
  • Thank you. I will try what you suggested. – Harutaka Kawamura Jan 08 '16 at 07:45

0 Answers0