Re: Help required on differential equation
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg1815] Re: Help required on differential equation
- From: rknapp (Robert Knapp)
- Date: Thu, 17 Aug 1995 00:03:23 -0400
- Organization: The Santa Fe Institute
In article <DDDr09.AzA at wri.com> Dr Brian Hunton tel 270502 <hunton at news.ox.ac.uk> writes:
...
>
> Please help! I have a differential equation that I solve numerically with
> Mathematica. This gives me my interpolating function f[x] which I can happily
> plot. Now I want to plot f''[x] over the same range, but I'm having all sorts
> of bother. Can anyone help? I'd be very grateful...
>
...
>
In principle this should cause no problem. For example, if I define sol by
In[1]:=
sol = NDSolve[{y'[x] == y[x],y[0] == 1},y,{x,0,1}]
Out[1]=
{{y -> InterpolatingFunction[{0., 1.}, <>]}}
then
Plot[Evaluate[y[x] /. sol[[1]]],{x,0,1}]
and
Plot[Evaluate[y''[x] /. sol[[1]]],{x,0,1}]
work equally well (and give basically the same plot in this case).
Note the Evaluate, however. In the first one, the plot can be done,
but will take a little longer without the Evaluate. For the second
derivative, the plot will take MUCH longer without the Evaluate. This
is because, since Plot has the attributew HoldAll, y'' is evaluated
for each numerical value plotted, and it takes a significant amout of
time to compute the derivative of an InterpolatingFunction object.
If you prefer not to need to remember to put an Evaluate in your Plot
commands, an equally effective alternative is to compute in advance.
FOr sol as defined above, I could produce the smae plots by:
f = sol[[1,1,2]];
Plot[f[x],{x,0,1}];
fpp = f'';
Plot[fpp[x],{x,0,1}];
Rob Knapp
WRI