I was trying to make an oscillation plot that could be manipulated depending on the value of $\beta$. The differential equation is below, and when I just plot the solution, it turns out to be the correct plot. However, when I insert the manipulate function, the plot returns a blank graph. Can anyone see what I am doing incorrectly?

    s = DSolve[{x''[t] + 2 β x'[t] + 4 x[t] == 0, x'[0] == 0, x[0] == 1}, x[t], t];

Manipulate[Plot[Evaluate[x[t] /. s], {t, 0, 5}], {β, 0, 4, 0.1}]
  • 2
    $\begingroup$ possible duplicate of Manipulate not showing anything $\endgroup$ – xzczd May 13 '15 at 2:24
  • 1
    $\begingroup$ It's the same essential problem, @xzczd, but I decided not to close it because there was another issue that I wanted to alert the OP to - see my answer. Happy to be overruled by the community if it comes to it. $\endgroup$ – Verbeia May 13 '15 at 3:40

There are two issues going on here, though only one of them is preventing your plot from working in the Manipulate.

The first is, as noted by xzczd in comments, that you need to get Mathematica to see that the \[Beta] in the expression for x[t]/. s is the same one you are using as the variable to be manipulated. You can see this is an issue with a slight variant to your Manipulate:

 Grid[Table[Evaluate[x[t] /. s], {t, 0, 4, 2}]], {\[Beta], 0, 4, 0.1}]

enter image description here

You can ensure this using a second replacement rule, like this:

   Simplify[Evaluate[x[t] /. s] /. \[Beta] -> b], {t, 0, 4, 2}]], {b, 0, 4, 0.1}]

enter image description here

The second is that there are trivial imaginary parts here, though in this case they don't seem to matter for the plot. If you ever hit this in a more material way, you can use Chop to get rid of them.

Here's the code that gets you the plot.

 Plot[Evaluate[x[t] /. s /. \[Beta] -> b], {t, 0, 4}], {b, 0, 4, 0.1}]

enter image description here

  • $\begingroup$ Thank you for the explanation! :) $\endgroup$ – John May 13 '15 at 5:11

Below is the answer:

 Evaluate[x[t] /. NDSolve[{x''[t] + 2 \[Beta] x'[t] + 4 x[t]== 0, 
  x'[0] ==   0, x[0] == 1}, x, {t, 0, 4}]],
  {t, 0, 5}], {\[Beta], 0,4,0.1}]

thank you for asking

  • $\begingroup$ It may be useful for the OP if you also pointed out the difference between your method and theirs, and why their method does not produce the desired plot. $\endgroup$ – MarcoB May 13 '15 at 3:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.