Re: Problem: Plotting list of {InterpolatingFunction[]}
- To: mathgroup at smc.vnet.net
- Subject: [mg2585] Re: Problem: Plotting list of {InterpolatingFunction[]}
- From: rknapp (Robert Knapp)
- Date: Mon, 27 Nov 1995 21:31:42 -0500
- Organization: Wolfram Research, Inc.
In article <DI9AuM.Bx at wri.com> Patrick Jemmer <paddy at sun4.bham.ac.uk> writes:
>
> Hello all: I am solving a set of DEs using NDSolve to produce
> a list of interpolating functions, where the list is called ans:
>
>
> In[5]:= ans
>
> Out[5]= {{source[t] -> InterpolatingFunction[{0., 1.}, <>][t],
>
> > sink[t] -> InterpolatingFunction[{0., 1.}, <>][t],
>
> > conc[t] -> InterpolatingFunction[{0., 1.}, <>][t],
>
> > a1[t] -> InterpolatingFunction[{0., 1.}, <>][t],
>
> > b1[t] -> InterpolatingFunction[{0., 1.}, <>][t]}}
>
> I then substitute with the list sp={source[t], sink[t], ... }
>
> intpf =sp/. ans
>
> Out[6]= {InterpolatingFunction[{0., 1.}, <>][t],
>
> > InterpolatingFunction[{0., 1.}, <>][t],
>
> > InterpolatingFunction[{0., 1.}, <>][t],
>
> > InterpolatingFunction[{0., 1.}, <>][t],
>
> > InterpolatingFunction[{0., 1.}, <>][t]}
>
>
>
> I am then trying to plot these together:
>
> Plot[intpf,{t,0,1}]In[7]:= Plot[intpf,{t,0,1}]
>
...
> and an empty plot....
You are running into problems with the HoldAll attribute of Plot.
Your problem has nothing to do with InterpolatingFunction objects per
se. For example:
vec = {x^2,x^3};
Plot[vec,{x,0,1}]
does the same thing. Why? Because Plot does not evaluate its
argument, it sees one item and assumes that it is to plot something
which evaluates to a real number for each value of x--not a vector.
The solution: wrap Evaluate[] around the first argument, as in
vec = {x^2,x^3};
Plot[Evaluate[vec],{x,0,1}]
or
Plot[Evaluate[intpf],{t,0,1}]
and you should get what you want.
Rob Knapp
WRI