0
|
15290 Views
|
3 Replies
|
2 Total Likes
View groups...
Share

# Problems using Manipulate to plot a parametric equation

Posted 10 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:
3 Replies
Sort By:
Posted 10 years ago
 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 10 years ago
 Thanks for the reply and your solution works perfectly. However, there still seems to be an inconsistency in the way Mathematica handles variables using the Manipulate command. The section of code I sent you was just a portion of the total code  see attached for complete file.In the complete file, I used two other variables speed and dist in addition to f, g and c. In the attached example, I cannot understand why the variable speed is not required to be inside the Manipulate command like the rest of the variables.Additionally, I created the file using an example. In the example, it appears that all the variables are in the same code block but just before the Manipulate command, and that code seems to work. Possibly the example is an older version, but it creates confusion.In any event, I am still interested in learning why the variable speed is treated differently than all the other variables used in the Manipulate command. Thanks,Mitch Sandlin Attachments:
Posted 10 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}]