Message Boards Message Boards

Plotting functions within a Manipulate

Posted 2 years ago

Hi Guys

Please refer to the attached notebook. It is something simple, for a bigger project. How do I get the plots to work using Manipulate? The notebook does not run currently with the plotting function.

POSTED BY: Mishal Mohanlal
3 Replies

A part from that, I would insert an Evaluate inside Plot:

Manipulate[c = 0.1*k*m;
 F = 1000;
 S = NDSolve[{m*x''[t] + k*x[t] == F*Sin[w*t], x'[0] == 0, x[0] == 0},
    x, {t, 0, 20}];
 Plot[Evaluate[{x[t], x'[t], x''[t]} /. S], {t, 0, 20}, 
  PlotLegends -> {"x", "y", "Theta"}], {k, 50, 266*1000}, {m, 100, 
  1000}, {w, 10, 1000}]

or, even better, use NDSolveValue:

Manipulate[c = 0.1*k*m;
 F = 1000;
 sol = NDSolveValue[{m*x''[t] + k*x[t] == F*Sin[w*t], x'[0] == 0, 
    x[0] == 0}, x, {t, 0, 20}];
 Plot[{sol[t], sol'[t], sol''[t]}, {t, 0, 20}, 
  PlotLegends -> {"x", "y", "Theta"}], {k, 50, 266*1000}, {m, 100, 
  1000}, {w, 10, 1000}]
POSTED BY: Gianluca Gorni

Thank you kindly

POSTED BY: Mishal Mohanlal
Posted 2 years ago

A syntax problem. Your definition of S ends with a comma. Replace it with a semicolon.

Manipulate[
    c = 0.1*k*m;
    F = 1000;
    S = NDSolve[{m*x''[t] + k*x[t] == F*Sin[w*t], x'[0] == 0, x[0] == 0}, x, {t, 0, 20}];
    Plot[{x[t], x'[t], x''[t]} /. S, {t, 0, 20}, PlotLegends -> {"x", "y", "Theta"}],
    {k, 50, 266*1000}, {m, 100, 1000}, {w, 10, 1000}
 ]
POSTED BY: Hans Milton
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract