Interpolation, ODEs and integration


gtlandi
07-02-2012, 05:27 AM
Dear forum members,

I oftenlly come upon a question whose setting has the following form (this is just an example)

Say I use the ODE libraries to solve a system of 2 differential equations. Then I want to integrate y1(x)+y2(x) from a to b.

A direct way is to implement a simple trapz rule for the data points of ode.out itself.

But I would like to have a more accurate approach. So the idea is to construct an interpolating function using Poly_Interp and then pass that function to any integration routine I want. So far I have not been able to find any efficient (and clean) way I doing this.

It seem I need to first create a new vector ym = y1+y2, then pass this vector to a functor containing the interpolation obj, and then pass this functor to the integration routine. Does anyone suggest a simpler way?

While I am at it: chapter 17 briefly describes how to use ODEs with an event function (say searching for g(x,y)=0). I haven't been able to implement this. Would anyone be willing to give an example?

I really appreciate any help on advance.

Best regards,

Gabriel