       FW: Plotting multiple outputs from cpu intensive functi

• To: mathgroup at smc.vnet.net
• Subject: [mg16933] FW: [mg16745] Plotting multiple outputs from cpu intensive functi
• From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
• Date: Thu, 8 Apr 1999 02:32:38 -0400
• Sender: owner-wri-mathgroup at wolfram.com

```Recall the recent discussion where Joel asked:

> ---------------------------
> 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?
> --------------------------

We can have some savings if we use a function (foo) that remembers it's
function values and we make sure we sample the second part of (foo) at the
points where it was already computed.  The lines of code below will do this.
As before Sin, Cos are not CPU intensive, but the method will apply to
functions that are.

In:=
foo[x_]:=foo[x]={Sin[x],Cos[x]}

In:=
Block[{\$DisplayFunction=Identity},
lst={};
gr1=Plot[lst={lst,x};Part[foo[x],1],
{x,0,\[Pi]/2}, PlotDivision->3, MaxBend->25];
lst=Union[Flatten[lst]];
pnts={#,Part[foo[#],2]}&  /@lst;
gr2=ListPlot[pnts,PlotJoined->True];
]
Show[gr1,gr2];

(* Graphics not shown *)

The only problem with the approach above is that the adaptive sampling
algorithm isn't used for the second function.  I still haven't found a way
to use the samples already computed, and use the plot function to perform
adaptive sampling on the second function where needed.

Joel indicated he would like Wolfram to make the source code available.  I
was thinking something along the same lines.  Actually I don't think anyone
has a legitimate need for the source code to compute things like
LerchPhi[2.3, 1.2, 1/2].  Besides WRI probably keep those algorithms closely
guarded.  But what about functions like Plot, FindRoot, NIntegrate?  Are
they implemented with nothing but Mathematica code?  I don't see why WRI
should not let us have the source code for functions like that.

Regards,
Ted Ersek

```

• Prev by Date: Re: Help needed with List!
• Next by Date: PoissonDistribution
• Previous by thread: Re: Plotting multiple outputs from cpu intensive functi