Plotting the solution of an ODE

  • Topic: Mathematica 
  • Thread starter Robin04
  • Start date
  • Tags Tags
    Ode Plotting
3 replies · 2K views · last reply
Robin04
Messages
259
Reaction score
16
I'm trying to plot the solution to an ODE (with given initial values) but there are some constants in it that I want to evaluate with sliders and I'm not sure what is the right syntax for this.

Code:
Manipulate[Plot[solution1[t], {t, 0, 10}, PlotRange -> {-Pi, Pi}],
{{a, 1, "Driving amplitude"}, 0, 10, Appearance -> "Labeled"},
{{g, 9.81, "Gravitational acceleration"}, 0, 10,
  Appearance -> "Labeled"},
{{l, 1, "Length"}, 0, 10, Appearance -> "Labeled"},
{{\[Gamma], 1, "Driving frequency"}, 0, 10, Appearance -> "Labeled"}]

Mathematica Manipulate panel with four sliders (Driving amplitude, Gravitational acceleration, Length, Driving frequency) above an empty plot axis from -1 to 1 and -3 to 3, with DSolve errors listed below.


Mathematica session: input solution1 := DSolve on SimplifiedEL1 with phi(0)=0 and phi'(0)=0, then output shows phi(t) = a γ² (Cos[√g t/√l] − Cos[t γ]) / (−g + l γ²).


If I copy solution1 explicitly into plot it works, but if I refer to it by the variable name it doesn't. What's the correct syntax for this?
 
Attachments
  • Mathematica Manipulate panel with four sliders (Driving amplitude, Gravitational acceleration, Length, Driving frequency) above an empty plot axis from -1 to 1 and -3 to 3, with DSolve errors listed below.
    K-pkiv-g-s.png
    34.3 KB · Views: 579
  • Mathematica session: input solution1 := DSolve on SimplifiedEL1 with phi(0)=0 and phi'(0)=0, then output shows phi(t) = a γ² (Cos[√g t/√l] − Cos[t γ]) / (−g + l γ²).
    K-pkiv-g-s.png
    12.9 KB · Views: 523
I have had consistent success with putting all the needed definitions and functions inside the Manipulate

Manipulate[
sol=p[t]/.DSolve[{a p''[t]==p[t],p[0]==0,p'[0]==a},p[t],t][[1]];
Plot[sol,{t,0,4}],
{{a,1},0,4}
]