MathGroup Archive 2009

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

Search the Archive

Re: Compute once question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105640] Re: Compute once question
  • From: David Bailey <dave at removedbailey.co.uk>
  • Date: Sun, 13 Dec 2009 05:38:02 -0500 (EST)
  • References: <hg00d9$j98$1@smc.vnet.net>

Michael Greene wrote:
> I'm having trouble getting Mathematica not to repeatedly compute values in a
> Manipulate Window. I'm not sure if it's a bug in my code or if it's a
> fundamental disconnect between what I think is going on and what Mathematica
> is actually doing.
> 
> What my code is doing is slicing a circle into segments, rotating the slices
> and then translating them. When  the process first starts out, I'm dealing
> with a small number of slices so the response is immediate. The process
> eventually works up to around 20 slices and the user begins to see a slight
> delay between manipulating the controller and seeing the result. At 100
> slices, we're talking about a 3 or 4 second lag which isn't OK.
> 
> When I first started the process, I was allowing the user to directly
> manipulate the slice count. When I saw the lags starting to kick in, I
> thought I'd just let the user control a step counter instead and based on
> which step the user was on, compute the graphic, store the graphic and reuse
> the stored graphic as we moved further into the process. That is:
> 
> If[Step<=8, <do intensive computation and store graphic in G>];
> Graphics[G];
> 
> So when Step gets to 9, I expect G to pop up on the screen right away but it
> doesn't. The program still takes several seconds as if it's recomputing G.
> Am I wrong to expect Mathematica to only compute G when Step is less than 9?
> I'd post the actual code but it's rather hoary. Hopefully my question still
> makes sense sans code.
> 
>  What I'd really like to be able to do is timeslice G's computation in the
> earlier steps when the user is spending time assimilating the earlier
> information so by the time he/she gets to the computationally expensive
> step, the work is done and G just pops onto the screen as if it's no big
> deal. But first things first...
> 
> Thanks,
> Michael
> 
> 
It is awfully hard to comment in detail without some actual code, but it 
may be worth adding counters to your code, such as

Global`couter1++;

If you zeroise all the counters before use (otherwise you will get nasty 
recursion errors) and move the Manipulate controls, you will be able to 
inspect the counters to determine how many times things got executed. I 
specified the Global` context just in case your code was nested in 
another context for one reason or another.

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: PolarPlot[Log[\[Theta]], {\[Theta], 0.27, 1.7 Pi}]
  • Next by Date: When to use Hermitian operator?
  • Previous by thread: Compute once question
  • Next by thread: Re: Re: Compute once question