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

MathGroup Archive 2010

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

Search the Archive

Problems with Module

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112068] Problems with Module
  • From: Docente Sergio Miguel Terrazas Porras <sterraza at uacj.mx>
  • Date: Sat, 28 Aug 2010 07:03:32 -0400 (EDT)

Hi John:

Thank you for responding.

The code does work for me with the empty list of local variables. Mathematica 7.0.1=
, Windows 7.

Now, the code with the list of local variables actually shows the trajectory and both vectors, unitario[t] and du[t] for t = 0. But as soon as I move the slider, things go wrong, as it tries to evaluate Derivative[1] ["a number"] of something.

As for your comments on Manipulate, I as a rule define all my functions inside Manipulate, but as I was very frustated, I was just trying everything (I actually saved the notebook with the name Frustating.nb).

It was actually by accident that I forgot to fill in the list of local variables. When it worked I was relieved. I then noticed my ommision and proceeded to fill the list. And then it didn't work!

Could I send you the actual notebooks?
I have a feeling that there is a problem with the cpoy-paste deal.

Thanks again !

Sergio Terrazas

John Fultz wrote:
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).

Sincerely,

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

Sergio Terrazas wrote:
 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: Problems with Module
  • Next by Date: Re: Clear variables in a list
  • Previous by thread: Re: Problems with Module
  • Next by thread: Re: Problems with Module