M=8; NN=8; m = M - 1; n = NN - 1; alpha = 5.;
beta = 4.; c = 0.05; T = 2.; h = (1. - 0.)/M;
k =T/NN
The problemequation is Subscript[u, t] + u Subscript[u, x] = c Subscript[u, xx]
$$\frac{\partial u(x,t)}{\partial t}+u(x,t) \frac{\partial u(x,t)}{\partial x}=c \frac{\partial ^2u(x,t)}{\partial x^2}$$
with initial condition
Subscript[u, x, 0] = (2. c beta Pi Sin[Pi Subscript[x, i]])
/ (alpha + beta Cos[Pi Subscript[x, i]])
$$u(x,0)=\frac{2 \pi \beta c \sin (\pi x)}{\alpha +\beta \cos (\pi x)}$$
and boundary conditionconditions
Subscript[u, 0, t] = 0; Subscript[u, 1, t] = 0;
$$u(0,t)=u(1,t)=0$$
I tried the backward finite difference (FD) for Subscript[u, t]
$\frac{\partial u(x,t)}{\partial t}$ and the central FD for the others. I wrote the following code, but I think there are some gaps in it. Because, the approximate solutions do not match the exact one
u[x_, t_] := (2 c beta Pi Exp[-c Pi^2 t] Sin[Pi x])
/ (alpha + beta Exp[-c Pi^2 t] Cos[Pi x]);
$$u(x,t)=\frac{2 \pi \beta c e^{-c \pi ^2 t} \sin (\pi x)}{\alpha +\beta e^{-c \pi ^2 t} \cos (\pi x)}$$
Note that Subscript[w, i, j]
stands for the approximation in the grid point $(x_i,t_j)$.