MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Plotting multiple outputs from cpu intensive functi

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16803] Re: [mg16745] Plotting multiple outputs from cpu intensive functi
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Tue, 30 Mar 1999 02:35:11 -0500
  • References: <7dbq3v$cf3@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Ersek, Ted R <ErsekTR at navair.navy.mil> wrote in message
news:7dbq3v$cf3 at smc.vnet.net...
> Joel wrote:
> ---------------------------
> 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?
> --------------------------
>
> Joel,
>
> I think you can solve your problem by defining a function that remembers
> values it has computed.  Here is a simple example that doesn't require
this
> trick, but it gets the point across.
>
> In[1]:=
> foo[x_]:=foo[x]={Sin[x],Cos[x]}
>
> In[2]:=
> Plot[{Part[foo[x],1],Part[foo[x],2]},{x,0,4}];
> (* Graphic not shown *)
>
>
> Regards,
>  Ted Ersek
> ------------

Ted,
One problem is that Plot[{f,g}, {x,a,b}] makes adaptive choices of x for f
and then independently for g. For this and maybe for other reasons the
remembered values may not be the ones needed. One way out might be to make
interpolating functions from the remembered values (a linear interpolation
would likely be sufficient). Of course we might then have to deal with
evaluating outside the data range.

Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565









  • Prev by Date: Re: combining two plots
  • Next by Date: Re: Equation numbers
  • Previous by thread: RE: Plotting multiple outputs from cpu intensive functi
  • Next by thread: Simplify: Which Sign