Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

When to use Module inside Manipulate

  • To: mathgroup at smc.vnet.net
  • Subject: [mg101025] When to use Module inside Manipulate
  • From: Porscha Louise McRobbie <pmcrobbi at umich.edu>
  • Date: Sun, 21 Jun 2009 07:05:59 -0400 (EDT)

Hello,

I have defined a 2D complex function, and made side-by-side animations 
of the Re/Im parts inside a Manipulate.

As written, I have the function definition as well as the animation 
wrapped in Module, and the animation/manipulate commands work fine 
(albeit slowly). However, if I remove that Module (it seems redundant 
to me), leaving only the outer DynamicModule, the cell where the 
graphs appear is highlighted, and the animate/manipulate no longer work.

Any ideas about what I'm doing wrong? I suspect I'm not understanding 
how to localize variables properly.

Thanks in advance,
Porscha



DynamicModule[{amp, phase, a, b},

  Manipulate[a = 1; b = 1;

   Module[{Psi, T},

    Psi[x_, y_] =
     Sqrt[1 - amp^2] Exp[-I \[Pi]^2/2  (4/a^2 + 1/b^2) T] 2/
       Sqrt[a b] Sin[(2 Pi x)/a] Sin[(Pi y)/b] +
      amp Exp[I phase] Exp[-I \[Pi]^2/2  (9/a^2 + 1/b^2) T] 2/
       Sqrt[a b] Sin[(3 Pi x)/a] Sin[(Pi y)/b] ;

    Animate[

     GraphicsRow[{Plot3D[Re[Psi[x, y] /. T -> t], {x, 0, 1}, {y, 0, 1},
         PlotRange -> {{0, 1}, {0, 1}, {-3, 3}},
        PerformanceGoal -> "Quality", ColorFunction -> "Rainbow",
        Mesh -> None],

       Plot3D[Im[Psi[x, y] /. T -> t], {x, 0, 1}, {y, 0, 1},
        PlotRange -> {{0, 1}, {0, 1}, {-3, 3}},
        ColorFunction -> "Rainbow", PerformanceGoal -> "Quality",
        Mesh -> None]}, ImageSize -> 600],

     {t, 0.001, 5}, AnimationRunning -> False, AnimationRate -> .05]],

   {{amp, 0.5}, 0, 1, Appearance -> "Labeled",
    ImageSize -> Small}, {phase, 0, 2 Pi, Appearance -> "Labeled",
    ImageSize -> Small}, ControlPlacement -> Left,
   SaveDefinitions -> True]]


  • Prev by Date: Re: compress lists with mean for equal elements
  • Next by Date: Re: Slow performance gathering property data from fitted
  • Previous by thread: Re: Slow performance gathering property data from fitted
  • Next by thread: Re: When to use Module inside Manipulate