# Is there any alternative for Manipulate or Animate?

I have a project to animate heat equation in 3D. I have the following problem

$$u_t=u_{xx},\qquad 0\leq x\leq 1 \land t>0$$ $$u(0,t)=u(1,t)=0$$ $$u(x,0)=\begin{cases} 2x, & 0\leq x<\frac{1}{2}\\ 2-2x, & \frac{1}{2}\leq x<1 \end{cases}$$

And then animate the comparison between exact solution and my manual solution within the time interval $$0 \leq t \leq 2$$. I try to solve using Mathematica with the command NDSolve, here's my code

sol = NDSolve[{D[u[x, t], t] == D[u[x, t], {x, 2}],
u[0, t] == 0, u[1, t] == 0,
u[x, 0] == Piecewise[{{2 x, 0 <= x <= 1/2}, {2 - 2 x, 1/2 <= x <= 1}}]},
u, {t, 0, 2}, {x, 0, 1}]
u[x,t]/.sol;
Manipulate[Plot3D[u[x, t] /. sol, {x, 0, 1}, {t, 0, 2}, PlotRange -> All, PlotPoints -> 250, Mesh -> None], {t, 0, 2}]


But my Wolfram Mathematica seems heavily working, it even hardly change the plot3D image, when I change the control value in Manipulate. Is there a way to fix this? Or is there any alternative better command?

• I'm sorry i have a trouble editing the equation it keeps getting me the "Your post appears to contain code that is not properly formatted" please help me edit it if you can May 30 at 3:24
• You're using {t, 0, 2} for both Plot3D's range specification and Manipulate's range specification, and I'm pretty sure that's not what you're trying to animate here? Edit: Conceptually, once Plot3D uses its t range, there should be no more t values to Manipulate. May 30 at 3:28
• @eyorble I change it to $u$, but still can't export it to .avi, well I can and it sometimes not responding but the result video is just the plot at t=0 not moving anywhere May 30 at 3:41
• PlotPoints -> 250 is not your friend, nor the friend of speed. Manipulate (Animate just makes a specialized Manipulate) is designed for computations that can be updated quickly. If you need an initial 250 plot point grid to make a reasonable plot, you probably cannot do it quickly. But as @eyorble seems to hint, maybe you want Plot[u[x, t] /. sol, {x, 0, 1}] instead with t controlled by Manipulate? May 30 at 4:04
• The problem comes from the fact that the initial condition is not compatible with your ODE. The second derivative D[u[x, 0], {x, 2}] at t==1/2 is infinite. Try to give an initial condition that gives a finite second derivative. May 30 at 14:41

it even hardly change the plot3D image, when I change the control value in Manipulate

I made some changes to make it run much faster now. ClearAll[u, x, t];
pde = D[u[x, t], t] == .1*D[u[x, t], {x, 2}];
bc = {u[0, t] == 0, u[1, t] == 0};
ic = u[x, 0] == Piecewise[{{2 x, 0 <= x <= 1/2}, {2 - 2 x, 1/2 <= x <= 1}}];
sol = NDSolveValue[{pde, ic, bc}, u, {t, 0, 2}, {x, 0, 1}];
Manipulate[
Plot3D[sol[x, t], {x, 0, 1}, {t, 0, t0}, PerformanceGoal -> "Speed",
PlotRange -> {Automatic, {0, 2}, {-.1, 1}},
AxesLabel -> {"x", "time", "u(x,t)"}, ImageSize -> 400],
{{t0, 0.01, "time"}, .01, 2, .01, Appearance -> "Labeled"},
TrackedSymbols :> {t0}
]


Removed PlotPoints -> 250 and added PerformanceGoal -> "Speed" and other minor cleanup.

• Thank you so much, but i think what i need is just changing to that 'PerformanceGoal->"Speed"', only 1 thing still stumble me, how do I export the file so its smooth on the video ? Seems like the 'Export' doesnt render all the value in time May 30 at 9:12
• You might try making a list of frames, then exporting that. (Also, ListAnimate might work better, because your frames are pre-rendered). May 30 at 15:50
• You could precompute the graphic frames and use ListAnimate. ListAnimate will also let you specify the frames per second. reference.wolfram.com/language/ref/… Jun 2 at 1:36