[SciPy-user] integrate.odeint and event handling

James tomo.bbe@gmail....
Wed Jan 21 14:44:23 CST 2009


A good point, well made. I naively thought the OP just wanted to stop
computation once f had gone negative, but thinking about it I suppose that
is pretty pointless if you can't figure that point in time out accurately or
efficiently. Sorry for the reading comprehension failure.

On Wed, Jan 21, 2009 at 8:33 PM, Rob Clewley <rob.clewley@gmail.com> wrote:

> Let's be clear about the expected functionality of this posted code...
>
> > So your example would read something like... (if not tested this btw...)
> >
> > # ------------------------------
> > import numpy as np
> > from scipy import integrate
> >
> > def df(f,t):
> >    return f-2.
> >
> > def df_stop(f,t):
> >    return f < 0.0
> >
> > f0 = 1.
> > t0 = 0.
> > t_max = 5.
> > nout = 100
> > ts = np.linspace(t0,t_max,nout)
> >
> >
> > fs = [f0,]
> > df_continue = True
> > i = 0
> > while df_continue:
> >     f = integrate.odeint(df,fs[i],[ts[i],ts[i+1]])
> >     i+=1
> >     if i==nout-1:
> >         df_continue = False
> >     elif df_stop(f[1][0],ts[i+1]):
> >         df_continue = False
> >     else:
> >         fs.append( f[1][0] )
> >
> > fs = np.array( fs )
> >
> >
>
> This won't stop integration at the actual time that the event occurred
> (the OP said he wants to stop when f=0 and I am assuming he means to
> some significant accuracy) - it only stops at some time after the
> event occurred, up to an error of the fixed step size. The whole point
> of the lsodar and pydstool routines is to be able to have an
> integration that stops precisely when an event occurs, up to a
> predetermined error tolerance. In this code, you would have to
> re-integrate between the last two time points (the one before and the
> one after the event) at much smaller time steps to discover where the
> event is more accurately. This is efficiently done in the other codes.
>
> -Rob
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20090121/1ed25e24/attachment-0001.html 


More information about the SciPy-user mailing list