Group Abstract Group Abstract

Message Boards Message Boards

Problems using Manipulate to plot a parametric equation

Posted 11 years ago

It does not appear that the program is recognizing constants a and b that defaults to 1 - See Attached. If I plug 1 into the formulas for a and b, the plot works fine. I am sure it is something that I am doing, or not doing, but I have read the help text and followed the examples and can't seem to get the Manipulate to work. I would certainly appreciate any help you could give.

f[t_]:= E^(-a * t )*Cos[b*t];

g[t_]:= E^(-a * t)*Sin[b*t];

c[t_]:= {f[t],g[t]};

Manipulate[Grid[
      {{Show[
         ParametricPlot[c[t],{t,0,B}, PlotStyle-> {Thick,Blue},  PerformanceGoal -> "Quality"],
         ListPlot[{c[B]}, PlotStyle-> {Black,PointSize[0.02]}], AxesLabel->{"x","y"}, 
              PlotRange->1.2, ImageSize-> Medium, AxesOrigin-> {0,0}] }} ],
    {B,0.00001,4 Pi},{{a,1},0.1,10},{{b,1},0.1,10}]
Attachments:
POSTED BY: Mitchell Sandlin
3 Replies

Well, Manipulate is a lexical scoping construct, like Module. Consider:

var = "global"; func[] := var; Module[{var = "local"}, func[]]

This correctly returns "global" and not "local", because the var scoped by the Module is different from any var outside the Module. See the lexical scoping docs for more information and examples.

The same goes for Manipulate. Your definition of f refers to the symbol b, but the b in the definition of f is not the same b as the b scoped by Manipulate. The definition of 'speed' doesn't refer to local Manipulate variables, so it doesn't have the scoping issues that f does.

As Simon suggested, one way to avoid this scoping problem would be to move the definition of f into the scoping construct. That works fine for Module, but can cause subtle problems for Manipulate. (For instance, if you had two copies of a Manipulate output, and each set f to be a function of local Manipulate variables, then f would be constantly redefined whenever you interact with either output.)

A solution which works better for Manipulate would be to pass local variables as arguments to your utility functions.

var = "global"; func[x_] := x; Module[{var = "local"}, func[var]]
POSTED BY: Lou D'Andria
Attachments:
POSTED BY: Mitchell Sandlin
Posted 11 years ago
Manipulate[

 f[t_] := E^(-a*t)*Cos[b*t];
 g[t_] := E^(-a*t)*Sin[b*t];
 c[t_] := {f[t], g[t]};

 Grid[{{Show[
     ParametricPlot[c[t], {t, 0, B}, PlotStyle -> {Thick, Blue}, 
      PerformanceGoal -> "Quality"], 
     ListPlot[{c[B]}, PlotStyle -> {Black, PointSize[0.02]}], 
     AxesLabel -> {"x", "y"}, PlotRange -> 1.2, ImageSize -> Medium, 
     AxesOrigin -> {0, 0}]}}],

 {B, 0.00001, 4 \[Pi]}, {{a, 1}, 0.1, 10}, {{b, 1}, 0.1, 10}]
POSTED BY: Simon Tyran
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard