MathGroup Archive 2008

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

Search the Archive

Re: Run initialization cells before dynamic cells

  • To: mathgroup at smc.vnet.net
  • Subject: [mg94286] Re: Run initialization cells before dynamic cells
  • From: Alexei Boulbitch <Alexei.Boulbitch at iee.lu>
  • Date: Tue, 9 Dec 2008 23:12:06 -0500 (EST)

Hi, Damon,

I am not quite sure that I understood you correctly. I had a situation with plenty 
of interactive demonstrations or Mathematica-based movies. At least some of them 
depended upon the same set of definitions of expressions. The latter for sure must 
be executed before the demonstrations.

Its is not clear why you have problems. Are there some reasons forcing you to keep 
a special cell structure of your notebook?
 
If this is the case, just put definitions of expressions necessary for demonstrations before 
the definition of the first demonstration that uses it. Of coarse you need to be careful, 
but that´s all.

There is a better solution. In this situation I placed all the preliminary definitions into 
one, very first cell of the notebook. This cell was executed first. After that I placed
cells with demonstrations.

Another still more beautiful possibility is to put all expression definitions into one notebook 
(even into a single cell of your first notebook), while cells with the demos - into another one. 
Evidently, you first execute your first notebook.

Finally, you could place both preliminarily definitions as well as definitions of demos 
into the first notebook, so that their execution will open a second notebook and 
the demos will be shown there.

If the last idea is of any help for you, find a simple example below. Put it into one 
or two cells (this is not important), and execute.

  
(* This cell contains a preliminary definition of the functions f[x,a] 
and g[b,Phi] as well as definitions of demonstrations *) 

  f[x_, a_] := x^a*Exp[-x];
g[b_, \[Phi]_] := Sin[b*\[Phi]];
example1 = 
  Manipulate[
   Plot[f[x, a], {x, 0, b}], {{a, 1}, 0, 3}, {{b, 2}, 1, 4}];
example2 = 
  Animate[PolarPlot[g[b, \[Phi]], {\[Phi], 0, 2 \[Pi]}, 
    PlotRange -> 1], {b, 0, 4}, Paneled -> False];
expr = Style["\!\(\*SuperscriptBox[\"x\", \"a\"]\) exp(-x)", Italic, 
   24, Red, Bold];



(* The following cell opens a new notebook with cells specified below \
*)

(* This specifies the first ...  *)

title1 = TextCell["My first demonstration", "Section"];
textCell1 = 
  TextCell["This is a function", Blue, 25, "Text", 
   TextAlignment -> Center];
eqnCell = ExpressionCell[expr, "Output"];
demoCell1 = ExpressionCell[example1];

(*... and the second group of cells*)

title2 = TextCell["My second demonstration", "Section"];
textCell2 = 
  TextCell["This is a still better function", Blue, 25, "Text", 
   TextAlignment -> Center];
demoCell2 = example2;

(* This creates the second notebook *)

nb = CreateDocument[{CellGroup[{title1, textCell1, eqnCell, 
      demoCell1}, 1], CellGroup[{title2, textCell2, demoCell2}, 1]}, 
   WindowSize -> {900, 900}];


Success, Alexei


I have a notebook in which I define lots of useful computations, then
I have a few Manipulate or other Dynamic cells to illustrate those
computations.

When I open the notebook, the Dynamic cells do not run properly
because the computations on which they depend have not been defined. I
tried marking the definitions as Initialization cells, but they are
still not executed before the Dynamic cells. (I open the notebook, I
get the "Dynamic Content" warning, I tell it to go ahead and display
the dynamic content, then the Dynamic cells are not displayed properly
because the initialization cells have not been run; later, when I
first try to execute a cell, I am shown the "Initialize Notebook?"
dialog, and I tell it to execute all initialization cells; finally,
all the content displays properly.)

The demos that I've looked at from wolfram.com all have single
Manipulate cells, which define inside them all the initialization
material. This isn't appropriate for me, because I have many different
Dynamic cells which all depend on the same definitions.

I tried adding this to my Dynamic cells:

Dynamic[CleverDisplay[...], Initialization :> FrontEndExecute
[FrontEndToken["EvaluateInitialization"]] ]

but (a) it doesn't work, i.e. the initialization cells are not
evaluated until I shift+enter to evaluate some cell in the notebook,
and (b) if I have several of these, I'm worried it will try to execute
the initialization cells several times.

I must just be doing this the wrong way. Any advice?

Damon.

-- 
Alexei Boulbitch, Dr., Habil.
Senior Scientist

IEE S.A.
ZAE Weiergewan
11, rue Edmond Reuter
L-5326 Contern
Luxembourg

Phone: +352 2454 2566
Fax:   +352 2454 3566

Website: www.iee.lu

This e-mail may contain trade secrets or privileged, undisclosed or otherwise confidential information. If you are not the intended recipient and have received this e-mail in error, you are hereby notified that any review, copying or distribution of it is strictly prohibited. Please inform us immediately and destroy the original transmittal from your system. Thank you for your co-operation.




  • Prev by Date: Re: Small question about Filling between two functions in a determined interval
  • Next by Date: Re: NIntegrate of Oscillatory integrand
  • Previous by thread: Re: Run initialization cells before dynamic cells
  • Next by thread: Re: Run initialization cells before dynamic cells