[SciPy-user] SciPy integrate.odeint with interpolation

Anne Archibald peridot.faceted@gmail....
Fri May 23 10:03:11 CDT 2008


2008/5/23 Lorenzo Isella <lorenzo.isella@gmail.com>:
> Dear All,
> I have often used integrate.odeint to integrate ODE's.
> Now, consider the case y'(t)=f, where f is not an analytical function
> but rather a (discrete) set of experimental values.
> I wonder if it possible to do something along these lines:
> (1) define a function g(t) which interpolates (maybe with a spline)
> the set of experimental measurements {f(t_i)}, i=1,2,...N.
> (2) Re-define the problem as y'(t)=g(t)
>
> Do you think that this approach is correct? Are there any pitfalls I
> should be aware of?

For the particular problem you describe - y'(t)=g(t), what you want is
actually the antiderivative of g(t). For this particular case, if you
use splrep/splev to produce g(t) interpolating f(t), you can use
splint to obtain definite integrals of the resulting function. (Be
aware that splrep and friends can use "smoothing" to fit experimental
data with errors, and make sure you don't use smoothing if it's not
what you want.)

More generally, you would have y'(t,y) = f(t_i,y_i); I'm not totally
sure what the best way is to handle this, but using an ODE integrator
on an interpolated right-hand side seems reasonable to me. It'll have
to be a bivariate spline, which puts some constraints on the sampled
points. You will, of course, not be able to trust the result to the
same degree of accuracy you could normally expect from an ODE
integrator, and in fact it may be a real challenge to tell whether the
spline is doing a good job interpolating your data.

Anne


More information about the SciPy-user mailing list