New answers tagged

1

There are basically two errors in your code: misplaced semicolons and not initializing n at the right point of the code. Also, I think it would good if you allowed the free variable to passed to f, rather than hard wiring it into f. f[x_?NumericQ, z_Symbol] := Module[{n, m = 1, output = 0, y}, While[m < 5, n = 1; While[n < 5, y = ...


1

As mentioned in the comments you are not suppressing the output of the While statements with a semicolon. However, you still will not get the result you are expecting because you have scoped z inside of Module and your output will return a variable that is no longer in scope (a Unique variable from the Module). An example of a Wolfram Language way of ...


3

Another option would be to use the With scoping construct With[{ x = Xm Cos[ω t + ϕ], v = -ω Xm Sin[ω t + ϕ], a = -ω^2 Xm Cos[ω t + ϕ] }, Animate[Plot[{x, v, a}, {t, -12.5, 12}, PlotStyle -> {Blue, Red, DarkGreen}], {{ω, 1.57}, 0, 6.28}, {{ϕ, 0}, 0, 10}, {{Xm, 1}, 0, 3}, AnimationRunning -> False] ]


4

Make the definition as function of all the variables. x[ω_, ϕ_, t_, Xm_] := Xm*Cos[ω t + ϕ]; v[ω_, ϕ_, t_, Xm_] := -ω*Xm*Sin[ω t + ϕ]; a[ω_, ϕ_, t_, Xm_] := -ω^2*Xm*Cos[ω t + ϕ]; Animate[ Plot[{x[ω, ϕ, t, Xm], v[ω, ϕ, t, Xm], a[ω, ϕ,t, Xm]}, {t, -12.5, 12}, PlotStyle -> {Blue, Red, Green}], {{ω, 1.57}, 0, 6.28}, {{ϕ, 0}, 0, 10}, {{Xm, 1}, 0, 3}, ...


1

Legends are heavily affecting the performance in Dynamic so I'd probably go with some hand made legends anyway: Manipulate[ Grid[{{ Dynamic @ Plot[{a Sin[x], a Cos[x]}, {x, 0, 2 Pi}] , LineLegend[ {RGBColor[0.368417, 0.506779, 0.709798], RGBColor[0.880722, 0.611041, 0.142051]}, TraditionalForm /@ {Dynamic[a Defer@Sin[x]], Dynamic[a ...


3

The FrontEnd has the habit of renaming variables, which is usually a good thing, but sometimes can be troublesome. One possibility is to evaluate the argument of Plot, e.g.: Manipulate[ NumberForm[ Plot @@ {{a Sin[x], a Cos[x]}, {x, 0, 2 Pi}, PlotLegends -> "Expressions", PlotRange -> {-2, ...


1

Algohi's post answers the above question while adhering to the OP's code very closely. I suggest abandoning such adherence for two reasons. Simpler code. Better localization of variables. Here is what I get by taking Algohi's work as a basis, but simplifying it without worrying about maintaining the structure of the OP's code: DynamicModule[{locators, ...


2

Something like this? DynamicModule[ {point1 = {4, 4}, point2 = {4.5, 4.5}, point3 = {5, 5}, point4 = {6, 6}, point5 = {6.5, 6.5}}, dataset = {point1, point2, point3, point4, point5}; p1 = LocatorPane[ Dynamic[dataset], Dynamic[ListPlot[dataset, PlotRange -> {{0, 10}, {0, 10}}]]]]; GraphicsRow[ {p1, Dynamic[ ...



Top 50 recent answers are included