Re: Problem with combination NDSolve NIntegrate
- To: mathgroup at smc.vnet.net
- Subject: [mg72758] Re: [mg72739] Problem with combination NDSolve NIntegrate
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Thu, 18 Jan 2007 05:34:21 -0500 (EST)
- Reply-to: hanlonr at cox.net
For comparison,
ti[t]/.DSolve[{ti'[t]==ti[t],ti[0]==a},ti[t],t][[1]]
a*E^t
Integrate[%/.t->5,{a,0,10}]
50*E^5
%//N
7420.66
Clear[trial];
trial[a_?NumberQ]:=
NDSolve[{ti'[t]==ti[t],ti[0]==a},ti,{t,0,10}][[1]];
Off[ReplaceAll::reps];
NIntegrate[ (ti[5] /. trial[a]), {a, 0, 10}]
7420.66
Although, in general I recommend that you use NumericQ rather than NumberQ
trial[E]
trial[E]
Clear[trial];
trial[a_?NumericQ]:=
NDSolve[{ti'[t]==ti[t],ti[0]==a},ti,{t,0,10}][[1]];
trial[Pi]
{ti -> InterpolatingFunction[{{0., 10.}}, <>]}
Bob Hanlon
---- Paul Schneider <paul.schneider at wu-wien.ac.at> wrote:
>
>
> I am using version 5.2
>
>
>
> NIntegrate tries to evaluate the integrand symbolically. I try to
>
> circumvent this by using ?NumberQ but without success. Please try the
>
> following toy example:
>
>
>
> trial[a_?NumberQ] :=
>
> NDSolve[{ti'[t] == ti[t] , ti[0] == a} , ti, {t, 0, 10}];
>
> NIntegrate[ (ti[5] /. trial[a]), {a, 0, 10}]
>
> Plot[ (ti[5] /. trial[a]), {a, 0, 10}]
>
>
>
> NIntegrate does not evaluate to a number and throws a warning, while I
>
> get a perfect plot from Plot.
>
>
>
> Does anybody know what to do?
>
>
>
> Cheers,
>
>
>
> Paul