[SciPy-user] Using odeint to solve complex-valued ode's
robert.kern at gmail.com
Fri Nov 17 16:02:02 CST 2006
David L. Goldsmith wrote:
> OK, I tried odeint(f, y0, t) where f is a complex-valued function of y
> and y' and was told:
> TypeError: a float is required in line 120 of odeint
> so I tried:
> odeint(real(f), real(y0), t)
> and was told:
> odepack.error: The function and its Jacobian must be callable in line
> 120 of odeint.
Calling real(f) where f is a function object won't do anything sensible. In
fact, what's happening is that numpy doesn't recognize it as an ndarray, so it
calls array(f) to make it an array. array() doesn't recognize it as any kind of
sequence or number, so it assumes that you wanted to treat it as a scalar type
numpy.object_ (the numpy scalar version of object arrays). I believe when faced
with an object array, real() simply returns its input just like it does for any
dtype that is not explicitly complex. The result is a scalar object, which is
not callable; thus, you get that exception.
> I also tried a few other ways I could think of, all failed. So it would
> appear that I must convert my complex-valued f into a real vector-valued
> function before passing it to odeint - if this is incorrect, please
> supply an example of how to construct things so that odeint will take a
> complex-valued f. Thanks!
This is correct from what I remember. I don't think that the underlying ODEPACK
handles complex-valued ODEs (except as converted to a real vector-valued ODE).
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the SciPy-user