0
$\begingroup$

I am trying to solve the Burgers equation $u_t=0.01 u_{xx}-u u_x,$ with $t>0, u(0,t)=u(1,t)=0, u(x,0)= 0.4 \sin {2 \pi x}.$

I’ve tried

n = 20; Subscript[h, n] = 1/n;
U[t_] = Table[Subscript[u, i][t], {i, 0, n}]
eqns = Thread[
D[U[t], t] == 
Join[{D[Sin[2 π t], t] + (Sin[2 π t] - Subscript[u, 0][t])}, 
ListCorrelate[{1, -2, 1}/Subscript[h, n]^2, 
  U[t], {1, 2}, {Subscript[u, n - 1][t]}]/100]]
initc = Thread[U[0] == Table[0, {n + 1}]]
lines = NDSolve[{eqns, initc}, U[t], {t, 0, 4}]
ParametricPlot3D[
Evaluate[Table[{i Subscript[h, n], t, 
First[Subscript[u, i][t] /. lines]}, {i, 0, n}]], {t, 0, 4}, 
PlotRange -> All, AxesLabel -> {"x", "t", "u"}]
solution = 
NDSolve[{D[u[x, t], t] == [1/100 D[u[x, t], x, x]] - 
 u[x, t] D[u[x, t], x], u[x, 0] == 0, 
u[0, t] == Sin[2 π t], (D[u[x, t], x] /. x -> 1) == 0}, 
u, {x, 0, 1}, {t, 0, 4}]
Plot3D[Evaluate[First[u[x, t] /. solution]], {x, 0, 1}, {t, 0, 4}, 
PlotPoints -> {14, 36}, PlotRange -> All]

I am too close, I think, but something is getting wrong. Any help?

$\endgroup$
3
  • $\begingroup$ Cancel the first and last square bracket in [1/100 D[u[x, t], x, x]] and apply MaxStepSize -> 10^-2 in NDSolve. $\endgroup$
    – Akku14
    Mar 25 '20 at 16:08
  • $\begingroup$ I am a beginner, could you write the whole commands? Thank you $\endgroup$
    – George
    Mar 25 '20 at 16:11
  • $\begingroup$ The same as yours but without the square brackets: solution = NDSolve[{D[u[x, t], t] == 1/100 D[u[x, t], x, x] - u[x, t] D[u[x, t], x], u[x, 0] == 0, u[0, t] == Sin[2 π t], (D[u[x, t], x] /. x -> 1) == 0}, u, {x, 0, 1}, {t, 0, 4},MaxStepSize -> 10^-2] . $\endgroup$
    – Akku14
    Mar 25 '20 at 16:12
1
$\begingroup$

Sorry, could not follow all your code. But here is solution using standard plot

ClearAll[u, x, t];
pde = D[u[x, t], t] == 1/100 D[u[x, t], {x, 2}] - u[x, t] *D[u[x, t], x];
bc = {u[0, t] == 0, u[1, t] == 0};
ic = u[x, 0] == 4/10 Sin[2 Pi x];
sol = NDSolve[{pde, ic, bc}, u, {x, 0, 1}, {t, 0, 5}]

Manipulate[
 Plot[Evaluate[u[x, t0] /. sol], {x, 0, 1}, 
  PlotRange -> {Automatic, {-.5, .5}}],
 {{t0, 0, "time"}, 0, 5, .01},
 TrackedSymbols :> {t0}
 ]

enter image description here

$\endgroup$

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.