# Trying to Animate Piecewise Solution to Inviscid Burger's Equation

So I've got a piecewise solution to an Inviscid Burger's Equation and I've been trying to plot the time evolution of my solution with Mathematica

u[x_, t_] = Piecewise[{{0, x < 0}, {(((Sqrt[1 + 4 xt] - 1)^(2))/(4 t^(2))),0 <= x <= t+1}, {1, t+1 < x}}]
Manipulate[Plot[u[x, t], {x, -1, 1}], {t, 0, 10}]


But for w/e reason, it doesn't seem to "animate." All I'm getting is a "still" plot. What's going on here? How can I fix/address this?

My piecewise solution:

$$u(x,t)= \begin{cases} 0, && x<0\\ \frac{(-1+\sqrt{1+4xt})^{2}}{4t^{2}}, && 0\leq x \leq t+1\\ 1, && t+1 < x \end{cases}$$

• does it work if you change xt to x*t in your code? Space is important in Mathematica. it becomes multiplication May 12, 2021 at 22:04

You need to change xt to x t, otherwise Mathematica is recognizing xt as another variable. You can also, use Animate to have an automated animation.

u[x_, t_] :=
Piecewise[{{0, x < 0}, {(((Sqrt[1 + 4 x t] - 1)^(2))/(4 t^(2))),
0 <= x <= t + 1}, {1, t + 1 < x}}]
Animate[Plot[u[x, t], {x, -1, 1}, PlotStyle -> {Red, Thick}], {t, 0,
10, 0.5}]


face palm Yea... that was it, the space between x and t...

u[x_, t_] = Piecewise[{{0, x < 0}, {(((Sqrt[1 + 4 x*t] - 1)^(2))/(4 t^(2))),0 <= x <= t + 1}, {1, t + 1 < x}}]

frames = Manipulate[Plot[u[x, t], {x, -1, 9}, PlotRange -> {{-1, 7}, {-0.5, 1.5}}], {t,0, 7}, ControlType -> Animator, AnimationRate -> 1, RefreshRate -> 60]

Export[NotebookDirectory[] <> "animation.gif", frames]