Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica Plotting the solution of an ODE

  1. Feb 12, 2019 at 6:01 AM #1
    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 (Text):
    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"}]


    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?
  2. jcsd
  3. Feb 12, 2019 at 6:32 AM #2


    Staff: Mentor

  4. Feb 12, 2019 at 6:32 AM #3


    Staff: Mentor

    I have found the same problem with Manipulate. I have not found a way around it.
  5. Feb 13, 2019 at 2:38 PM #4
    I have had consistent success with putting all the needed definitions and functions inside the Manipulate

    sol=p[t]/.DSolve[{a p''[t]==p[t],p[0]==0,p'[0]==a},p[t],t][[1]];
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?