I am trying to plot the solution to the following PDE with the help of mathematica, however, when trying to employ manipulate to animate the behavior, I find that if I try this:

sol = DSolve[{D[u[t, x], t] - x*D[u[t, x], x] == 0, u[0, x] == 1/((x^2) + 1)}, u[t, x], {t, x}]

Manipulate[Plot3D[u[t, x] /. sol, {t, 0, 10}, {x, -10, 10}, PlotRange -> 1], {t,0.001, 10}]

I get just an empty graph.

On the other hand, If I try this:

Manipulate[Plot3D[u[t, x] /. sol, {t, 0, n}, {x, -10, 10}, PlotRange -> 1], {n,0.001, 10}]

I do get a plot of the solution, but when I move the slider the image becomes distorted and does not update fluidly.


Is this some sort of a problem with how my machine is rendering this plot, or do I need to implement a solution within the code?

Many thanks for the help.


You can control the automatic switching between when a control (e.g. slider) is actively being moved and when it has been releeased with ControlActive.

Better rendering takes more time, so it is up to the programmer to balance quality and speed, if the Automatic setting is unsatisfactory. See also PerformanceGoal.

sol = DSolve[{D[u[t, x], t] - x*D[u[t, x], x] == 0, 
   u[0, x] == 1/((x^2) + 1)}, u, {t, x}]

 Plot3D[u[t, x] /. sol, {t, 0, n}, {x, -10, 10}, PlotRange -> 1, 
  MaxRecursion -> ControlActive[1, Automatic], 
  PlotPoints -> ControlActive[15, 25], 
  Mesh -> ControlActive[None, Automatic]], {n, 0.001, 10}]

To fully understand how Manipulate works, read the four tutorials, the introductions and advanced ones, on Dynamic and Manipulate linked at the top of the documentation page of Manipulate.

The first try of the OP does not work because the instances of t in the Manipulate are localized in a DynamicModule created by Manipulate, while the t in sol is in the "Global`" context. That problem can be avoided by having DSolve return a replacement rule in terms of a function, as I did above.


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