[SciPy-User] Odeint Integration Method and its time step
Sun Dec 13 11:07:34 CST 2009
2009/12/13 Athanasios Anastasiou <email@example.com>:
> Hello everyone
> I am trying to run some simple examples with odeint in order to get a
> better understanding of it but amongst other things i am a little bit
> confused by the time parameter (t) that is passed to the function (f).
> The specific questions that i have are:
> 1) What exactly does t represent in the derivatives function f? Is it
> absolute time?
Yes, t is absolute time.
> 2) Which method is odeint using to integrate the derivatives function
> and why does it call it more than one time for the same time instance?
In general, in a system of ODEs, you have
Y' = f(Y,t)
That is, Y is a vector, and the time derivative of Y is given by a
function of Y and t. That is, the derivative you calculate is allowed
to depend not just on time but also on the position. Thus you can
solve something like dy/dt = y to get an exponential, or dy/dt = t to
get t**2/2, or some combination of the above.
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.
It may also occur that it evaluates f(Y,t) more than once. This is
redundant, and in an ideal world odeint would simply remember the
value. But odeint is a complex piece of code, and it may not have been
simple to arrange that it never repeats a value.
> 3) Considering the following odeint scipy examples:
> 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.
Incidentally, if you want to evaluate a second-order ODE, you should
convert it into a system of first-order ODEs.
More information about the SciPy-User