1
$\begingroup$

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} $

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

2 Answers 2

1
$\begingroup$

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}]
$\endgroup$
0
$\begingroup$

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]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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