[SciPy-user] question about ODE output and time steps
Thu Apr 26 10:38:08 CDT 2007
On 26/04/07, Trevis Crane <email@example.com> wrote:
> 1) The Y output from ode seems to be of type array. That is, I'm
> solving a system of three coupled equations, so for each iteration the
> solver generates an array of three elements as well as the time at that
> iteration. So, as you can see in my code, I append the output from each
> iteration. This ends up giving me a list of three-element arrays. This
> seems to be a rather cumbersome way of organizing the output and makes
> plotting it rather laborious. The only way I've been able to plot it is by
> running a for-loop in which I populate three other lists (y1,y2,y3) with the
> appropriate values from the ode solver. Then I can plot it (see attached
> code). As I said, this seems overly-laborious. Any suggestions?
The plotting functions are a pain, really, I almost always have to do
something to rearrange my data before I can plot it. The errorbar
functions are the worst. But the rearrangements can be made less
I suggest, before plotting, applying array() to your list; then you
can use slicing to feed the plotting functions:
A = array(L)
> 2) The basic solver scipy.integrate.ode requires you to specify the
> time step. I would prefer a solver with an adaptive time step algorithm.
> What do you suggest I do for this?
In fact it *is* an adaptive algorithm, they both are (odeint is just
as basic). But they are quite clumsy to use. There is an option which
will tell odeint to return after just one step of the internal
If you're doing anything even moderately sophisticated (such as, for
example, stopping on a particular y value, or obtaining a solution
object you can treat like a function) I would look at PyDSTool.
Anne M. Archibald
More information about the SciPy-user