[SciPy-User] Odeint Integration Method and its time step

Athanasios Anastasiou athanastasiou at googlemail.com
Mon Dec 14 05:03:18 EST 2009


Hello Anne

Thank you for your response, please see below:

> In order to solve such a thing, odeint needs to evaluate f(Y,t) at
> various values of Y and t. It may well occur that it tries f(Y1,t) and
> f(Y2,t) or f(Y,t1) and f(Y, t2). This is just the integrator trying to
> map out the derivative function.
Exactly, so (t) must somehow contribute to the return value of f, otherwise the
integrator would not call it at different values of (t) to "map the
derivative function"

> > 3) Considering the following odeint scipy examples:
> > http://www.scipy.org/Cookbook/CoupledSpringMassSystem
> > and
> > http://www.scipy.org/LoktaVolterraTutorial
> > Why isn't time (or the time step) taken into account within the
> > function that returns the derivatives at each time instant?
>
> Because in those examples, the derivative only depends on time through
> the function value. This is like the y' = y equation, where there is
> no explicit dependence on t.
>
> As for depending on the time step, that is a different question. Your
> right-hand-side function should not know anything about the time
> steps, since they are a detail of how the solver works. All knowledge
> of time steps is hidden inside the solver itself, and your code should
> never need to know what they are. This is important because odeint is
> an adaptive solver that adjusts its time steps as necessary to obtain
> the desired accuracy. In regions where the solution has simple
> behaviour, it will take big steps, while any place the solution has
> complex behaviour it will (should) take much smaller steps.

This is all understood but doesn't answer the question (or somehow, i
don't get it).

You need to know how long was an object accelerating for to derive its velocity
and also how long did the object travel at that velocity to derive its
displacement. This can only be known to (f) through the variable (t). So, if
there is time dependence (as in the case of a spring-mass system), it should be
somehow taken into account within (f)

> Incidentally, if you want to evaluate a second-order ODE, you should
> convert it into a system of first-order ODEs.
Which is what i have done in the code following my previous message. There is
one first order equation for the velocity of the mass which is then
fed to the second first order equation which returns
displacement.

All the best
Athanasios



More information about the SciPy-User mailing list