Re: Integrating Interpolating function
- To: mathgroup at smc.vnet.net
- Subject: [mg120700] Re: Integrating Interpolating function
- From: Andrew Moylan <amoylan at wolfram.com>
- Date: Wed, 3 Aug 2011 19:56:26 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
Depending on your application, it might also be convenient to better to get the integral out of NDSolve itself.
Compare:
In[13]:= s =
y /. First[
NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 30}]];
NIntegrate[t*s[t], {t, 0, 30}]
Out[14]= 46.9655
And:
In[15]:= f[30] /.
First[NDSolve[{f'[x] == x y[x], f[0] == 0,
y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, {f, y}, {x, 0, 30}]]
Out[15]= 46.9655
----- Original Message -----
> From: "Oliver Ruebenkoenig" <ruebenko at wolfram.com>
> To: mathgroup at smc.vnet.net
> Sent: Thursday, August 4, 2011 9:20:37 AM
> Subject: Re: Integrating Interpolating function
>
> On Wed, 3 Aug 2011, math_new wrote:
>
> > Hi,
> >
> > I solve a system of differential equations using NDSolve up to time
> > t_end. which gives me something like
> >
> > sol = {f->InterpolatingFunction}
> >
> > Now I want to do an integral like that
> >
> > Integrate[t*f[t],{t,0,tend}]
> >
> > but it won't be computed. What am I doing wrong?
> >
> > Cheers
> >
> >
>
> Hi
>
> s = NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 30}]
> NIntegrate[t*s[t], {t, 0, 30}]
>
> does what you are looking for.
>
> Hth,
> Oliver
>
>