[SciPy-user] Specific Odeint Problem

Rob Clewley rob.clewley@gmail....
Sun Feb 15 11:36:16 CST 2009


Ted,

> 3. At each time step, a specific resistance value from the
> aforementioned data set must be used in the solution of the ODE set
> e.g dydt = 4.56 * exp(resistance)/F

You are supplying odeint with a python function ("f") that returns the
right hand side. You need to define a second, auxiliary function that
takes the time t and returns the value for the resistance. Then you
can call that function from within your RHS function, so resistance in
the above expression for dydt will become resistance(t). t is already
an argument to the RHS function f, so you can just use that.

As for the auxiliary function, you could use interp1d from
scipy.interpolate, which takes the time domain as an array of values
defining (potentially non-uniform length) intervals, and a
corresponding 1D array of values (your resistances) and will linearly
interpolate between the values. I have code to do this with piecewise
constant values if you *really* need them to be constant on each time
interval. But I suspect you'd like these values to be smooth if
possible...

-Rob


More information about the SciPy-user mailing list