MathGroup Archive 2010

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

Search the Archive

Re: Problems with Module

  • To: mathgroup at
  • Subject: [mg112064] Re: Problems with Module
  • From: John Fultz <jfultz at>
  • Date: Sat, 28 Aug 2010 07:02:49 -0400 (EDT)

Actually, this does not work for me if I empty the Module list of variables. 
There might be something wrong with the example you intended to post as you
copied it here.  But I can make a generic point without seeing specific,
functioning code.

Manipulate uses Dynamic internally.  Dynamic works by deferring the evaluation
of its contents until they're displayed onscreen (i.e., well after the time you
press Shift+Enter and most other evaluation would happen).  By the time the
Manipulate is displayed onscreen, the local variables for the Module have
already gone out of scope.

A Module *inside* of Manipulate would work fine, since it will be evaluated as
part of the display.

Also, by having function definitions outside of the Manipulate, you guarantee
that, even if things did work, they won't work when you quit and restart
Mathematica and reload the file, until you reevaluate all of your defining
functions.  A good, self-contained Manipulate will define its own functions,
often doing so either explicitly with the Initialization option or implicitly
with the SaveDefinitions option (both of which are clearly documented...I'll
leave it to you to read up on them).


John Fultz
jfultz at
User Interface Group
Wolfram Research, Inc.

On Fri, 27 Aug 2010 04:07:29 -0400 (EDT), Docente Sergio Miguel Terrazas Porras
> Hi!
> The following is a slight modification of a code that works fine. But this
> one does not work.
> However, if I empty the list of local variables in Module, Then it works!
> Could some of you enlighten me?
> f[t_]:==4 Sin[t];g[t_]:==2 Cos[t];a==0;b==2\[Pi];
> DerVectConst[f,g,a,b]
> DerVectConst[f_,g_,a_,b_]:==Module[{r,vel,acel,unitario,derivadadeu,du},
> $Assumptions==t\[Element]Reals;
> r[t_]=={f[t],g[t]};
> vel[t_]==(r^\[Prime])[t];
> acel[t_]==(r^\[DoublePrime])[t];
> unitario[t_]==acel[t]/Norm[acel[t]];
> derivadadeu[t_]==(unitario^\[Prime])[t];
> du[t_]==derivadadeu[t]//FullSimplify;
> Manipulate[
> f1==Graphics[{Thick,Blue,Arrow[{r[t],r[t]+du[t]}]}];
> f2==Graphics[{Thick,Green,Arrow[{r[t],r[t]+unitario[t]}]}];
> g1==ParametricPlot[r[t],{t,a,b},AspectRatio->Automatic,PlotStyle->{Thick,
> Red}];
> txt==Graphics[{Text[Style["\!\(\*OverscriptBox[\"u\",
> \"^\"]\)",18,Bold],(r[t]+1.1unitario[t])],Text[Style["\!\(\*
> OverscriptBox[\"u\",
> \"^\"]\)^\[Prime]",18,Bold],(r[t]+1.1du[t])]}];
> punto==Graphics[{PointSize[.02],Point[r[t]]}];
> Show[g1,f1,f2,txt,punto,PlotRange->All]
> ,{t,a,b}]
> ]

  • Prev by Date: Re: Why is Newton's method failing to "find sufficient increase in function"?
  • Next by Date: Problems with Module
  • Previous by thread: Re: Problems with Module
  • Next by thread: Problems with Module