# Burgers equation

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}]
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?

• Cancel the first and last square bracket in [1/100 D[u[x, t], x, x]]  and apply MaxStepSize -> 10^-2  in NDSolve. Mar 25 '20 at 16:08
• I am a beginner, could you write the whole commands? Thank you Mar 25 '20 at 16:11
• 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]  . Mar 25 '20 at 16:12

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