[SciPy-user] question about ODE output and time steps

Trevis Crane t_crane at mrl.uiuc.edu
Thu Apr 26 11:50:55 EDT 2007



> -----Original Message-----
> From: scipy-user-bounces at scipy.org
[mailto:scipy-user-bounces at scipy.org] On
> Behalf Of Anne Archibald
> Sent: Thursday, April 26, 2007 10:38 AM
> To: SciPy Users List
> Subject: Re: [SciPy-user] question about ODE output and time steps
> 
> On 26/04/07, Trevis Crane <t_crane at mrl.uiuc.edu> 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
> painful.
> 
> I suggest, before plotting, applying array() to your list; then you
> can use slicing to feed the plotting functions:
> A = array(L)
> plot(A[:,0],A[:,1])
[Trevis Crane] 

ah, yes, good... thanks 

> 
> > 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
> integrator.
> 
> 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.
> 
[Trevis Crane] 

I assumed it was fixed since you supply the dt value (or in the case of
odeint, an array of t values).  By you statement above, though, I assume
these are simply to tell the solver at what times you want y information
(much like MATLAB's solvers).

What I really want to do, however, requires that I stop the solver at
some iteration step that, a priori, is unknown.  I'm simulating a
dynamic system and my condition for stopping the solver is when the
energy of the system stops changing beyond a specified threshold.  So
each iteration of the solver I calculated the energy, and if after so
many iterations it stops changing (much), I want the solver to stop.  

As for PyDSTool -- I'll check it out.  

thanks again,
trevis


> Anne M. Archibald
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user



More information about the SciPy-User mailing list