Message Boards Message Boards

0
|
5803 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Save CPU while using Manipulate[] in a notebook?

Posted 8 years ago

I have had this problem for a long time..

When a open a notebook where I have worked previously with Manipulate[] (even with simple ones), I am asked whether or not I want to Enable Dynamics. If I do enable, I get a bunch of errors and I understand why I get them: a lot of my variables were not initialized.

Now, this is bearable, what isn't really pleasurable is that Manipulate[] runs as Dynamic[]. As soon as I initialize the variables and the functions (and don't perform any changes), the program runs as it is being updated continuously and consumes 50% of my CPU. Simply having the Manipulate[] function in the notebook shouldn't be so expensive.

I have uploaded a notebook for you to have a look.

Please teach me how to optimize this.

Attachments:
POSTED BY: Sandu Ursu
3 Replies
Posted 8 years ago

Thank you very much, David!

POSTED BY: Sandu Ursu

In more recent versions of Mathematica, there is a list of trusted folders/directories. If your notebook is in one of these it will not ask before enabling Dynamic content. If it is not, it will.

The default folder is called Wolfram Mathematica. You can add your favorite folder to the list in preferences.

Your manipulate is trying to keep track of the symbols Subscript[x, b] andSubscript[x, s] which are not changing. The way to make Manipulate stop looking at those is to use the TrackedSymbols option to tell it what to really pay attention to as in this:

Manipulate[
 BarChart[100 {100 Subscript[x, S], Subscript[x, b]}/W /. 
   MaxUtility[W, p, \[Gamma], r], ChartLayout -> "Percentile", 
  AspectRatio -> 1/5, 
  ChartLabels -> Placed[{"Stocks", "Bonds"}, Center], 
  BarOrigin -> Left, ImageSize -> 800], {{W, 100}, 1, 
  1000}, {{p, 0.5}, 0, 1}, {{\[Gamma], 0.5}, 0, 
  3}, {{r, 0.095}, -0.01, 0.15},
 TrackedSymbols :> {p, \[Gamma], r}]
POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract