Plotting multiple outputs from cpu intensive function
- To: mathgroup at smc.vnet.net
- Subject: [mg16745] Plotting multiple outputs from cpu intensive function
- From: jns1 <jns1 at madmax.hrl.HAC.COM>
- Date: Wed, 24 Mar 1999 02:23:55 -0500
- Organization: LRH
- Sender: owner-wri-mathgroup at wolfram.com
Here is one that has stumped me for a while.
Now I need to do it again, and would appreciate any advice.
Say you are using a module to calculate something that takes quite a
LONG while.
It has 2 or more outputs in an output list, or whatever is convenient:
f[x_]:=Module[{...},
...long cpu intensive stuff...;
{out1,out2}]
out1 and out2 are calculated together because they are closely related
and share a lot of the needed cputime. How would you go about plotting
out1 and out2 together in the same graph without duplicating the
cputime?
The obvious is
Plot [f[x],{x,x1,x2}]
but it doesn't work because it tries to plot f[x] before evaluating f[x]
as a list and bombs.
This suggests trying Evaluate[f[x]] instead of f[x] in the plot
statement, which
does work if it is o.k. to immediately evaluate f[x] before the
plotting. But of
course this seldom is doable. In my case there are numerical
integrations or inputting
from files going on, so delayed evaluation must be used.
So I am stuck with 2 alternatives:
1) Make a table of values of {out1,out2}'s for different x's and then
use ListPlot or
2) Make 2 separate functions, f1[x_]:=f[x][[1]], and f2[x_]:=f[x][[2]]
and use
Plot[{f1[x],f2[x]},{x,x1,x2}]. This works fine, but it DOUBLES the cpu
time, for no reason.
Is there perhaps some combination of Hold's, Evaluate's, or whatever
where I can plot
things like this together conveniently?
Thanks,
Joel
- Follow-Ups:
- Re: Plotting multiple outputs from cpu intensive function
- From: "Wolf, Hartmut" <hwolf@debis.com>
- Re: Plotting multiple outputs from cpu intensive function