# [SciPy-user] odeint and complex coupled differential equations

Mark Everitt mark_everitt at msn.com
Fri Jun 23 07:17:47 CDT 2006

Hi everyone,

I'm having a problem with odeint and complex numbers. I have a
coupled differential equation:

def hyper10101(c,t,d,g):
dc = array(zeros(11,Complex32))
dc[0]   = 1j*d[2]*c[0]  + 2j*d[4]*c[0]  - 1j*g[4]*c[1]*sqrt(2)
dc[1]   = 1j*d[2]*c[1]  + 1j*d[4]*c[1]  - 1j*g[4]*c[0]*sqrt(2) - 1j*g
[5]*c[2]*exp(1j*(d[5]-d[0])*t)
dc[2]   = 1j*d[0]*c[2]  + 1j*d[2]*c[2]  + 1j*d[4]*c[2] - 1j*g[5]*c[1]
*exp(1j*(d[0]-d[5])*t) - 1j*g[0]*c[3]
dc[3]   = 1j*d[2]*c[3]  + 1j*d[4]*c[3]  - 1j*g[0]*c[2] - 1j*g[1]*c[4]
dc[4]   = 1j*d[1]*c[4]  + 1j*d[2]*c[4]  + 1j*d[4]*c[4] - 1j*g[1]*c
[3] - 1j*g[2]*c[5]
dc[5]   = 1j*d[1]*c[5]  + 1j*d[4]*c[5]  - 1j*g[2]*c[4] - 1j*g[3]*c[6];
dc[6]   = 1j*d[1]*c[6]  + 1j*d[3]*c[6]  + 1j*d[4]*c[6] - 1j*g[3]*c
[5] - 1j*g[4]*c[7] #- 1j*g[6]*c[9]
dc[7]   = 1j*d[1]*c[7]  + 1j*d[3]*c[7]  - 1j*g[4]*c[6] - 1j*g[5]*c[8]
*exp(1j*(d[5]-d[0])*t)
dc[8]   = 1j*d[0]*c[8]  + 1j*d[1]*c[8]  + 1j*d[3]*c[8] - 1j*g[5]*c[7]
*exp(1j*(d[0]-d[5])*t) - 1j*g[0]*c[9]
dc[9]   = 1j*d[1]*c[9]  + 1j*d[3]*c[9]  - 1j*g[0]*c[8] - 1j*g[1]*c
[10]*sqrt(2)
dc[10] = 2j*d[1]*c[10] + 1j*d[3]*c[10] - 1j*g[1]*c[9]*sqrt(2)
return dc

d = array([d1,d2,d3,d4,d5,d6])
g = array([gab,gbc,gcd,gde,gef,gfa])

And the elements of these are floats. I call odeint like this:

Y = odeint(hyper10101,c10101,tt,args=(d,g))

This returns the error:

TypeError: array cannot be safely cast to required type
odepack.error: Result from function call is not a proper array of
floats.

Are complex numbers broken for this, or am I just missing something?

Mark