[SciPy-user] odeint and complex coupled differential equations
Nils Wagner
nwagner at iam.uni-stuttgart.de
Fri Jun 23 08:26:38 EDT 2006
Mark Everitt wrote:
> 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
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user
>
AFAIK. you can't use odeint with complex inputs, but you can double the
size of your ODE
\dot{z} = f(z,t)
\dot{x}+i \dot{y} = \Re{f} + i \Im{f}
where i = \sqrt{-1}
\dot{x} = \Re{f(z,t)}
\dot{y} = \Im{f(z,t)}
The initial conditions are
x_0 = \Re{z_0}
y_0=\Im{z_0}
Nils
More information about the SciPy-User
mailing list