Clear[u];Clear[A];Clear[B];Clear[a];Clear[b]

Start by clearing variables and setting initial conditions.

Do[u[0,j]:=0,{j,0,50,1}]

Do[u[0,j]:=-3(.6-(j/50))*(.8-(j/50))*j,{j,30,40,1}]

Now fix the boundary conditions.

Do[u[n,0]:=0,{n,1,100}]

Do[u[n,50]:=0,{n,1,100}]

Check to make sure that the initial conditions are set correctly.

t=Table[N[u[0,j]],{j,0,50}]

U[0]=Table[N[u[0,j]],{j,1,49}]

Set the size of the parameter s.

s=0.3

Enter the matrices A and B in the Crank-Nicolson scheme.

A=Array[a,{49,49}];

Do[Do[a[j,k]=0,{j,1,49}],{k,1,49}]

Do[a[j,j]=(1+s),{j,1,49}];Do[a[j,j+1]=-s/2,{j,1,48}];Do[a[j+1,j]=-s/2,{j,1,48}]

a[3,2]

MatrixForm[A]

B=Array[b,{49,49}];

Do[Do[b[j,k]=0,{j,1,49}],{k,1,49}]

Do[b[j,j]=(1-s),{j,1,49}];Do[b[j,j+1]=s/2,{j,1,48}];Do[b[j+1,j]=s/2,{j,1,48}]

MatrixForm[B]

Do[U[m+1]=Inverse[A].B.U[m],{m,0,20}]

Check (and plot) the value at n=3.

U[3]

ListPlot[U[3],Joined->True,PlotRange->{0,1}]

Check and plot the value at n=10.

U[10]

ListPlot[U[10],Joined->True, PlotRange->{0,1}]