Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2011

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

Search the Archive

What is the point of having Initializations in DynamicModule and Manipulate?

  • To: mathgroup at
  • Subject: [mg122983] What is the point of having Initializations in DynamicModule and Manipulate?
  • From: Armand Tamzarian <mike.honeychurch at>
  • Date: Sat, 19 Nov 2011 06:46:53 -0500 (EST)
  • Delivered-to:

I'd be interested in feedback from other users about the way in which
Initializations works within DynamicModule (and Manipulate?). It is
fair to say that I expected an initialization to occur "initially."
That is to say I expected Initialization content to be evaluated prior
to the body of the DynamicModule. I have exchanged emails with tech
support about this. Attached is an example sent to me by tech support.

ClearAll[plot, g];

(* and in a separate cell *)
DynamicModule[{c}, {plot, Slider[Dynamic[c]], g[Dynamic@c]},
 Initialization :> (g[x_] := Cos[x]; plot = Plot[g[x], {x, 1, 10}]),
 UntrackedVariables -> {g}]

It is important for this example to keep the ClearAll line in a
separate cell so that the global variables are only cleared once. On
my system (OS X 10.6.8, Mma 8.0.4) the output is a list

 {plot, "slider", g[0.]}

where "slider" is the actual rendered slider but plot is the word
(unset variable) plot. In other words Global`plot has no value at the
time the body of the DynamicModule is evaluated. Ditto Global`g.

If you evaluated the cell (the second cell with the DynamicModule) a
second time a plot graphic appears in the list and g[0.] becomes
Cos[0.]. This is not surprising because Global`plot and Global`g now
have a value.

Wolfram have indicated that this is working as designed -- which is
presumably why this example was sent to me of how this should work. If
that is the case it seems poorly designed because (and it is here I
would like feedback) users would expect initializations to be
evaluated prior to the body of the DynamicModule -- otherwise what is
the point?

I'd appreciate the thoughts of other users about this.

Additionally I have been told by Wolfram that wrapping Dynamic around
the variable(s) that are not being evaluated will trigger the
evaluation. But why would a user want to make plot or g Dynamic? It
seems to me that the entire purpose of having an Initialization is to
evaluate this "one off" variable/functions.



  • Prev by Date: Integrating a rotated function inbetween two circles
  • Next by Date: Re: How to force integers
  • Previous by thread: Re: Data binning with CUDA
  • Next by thread: Re: What is the point of having Initializations in