Clear[U]

Start by clearing variables and setting initial conditions.

Do[U[0,n]:=0,{n,0,10,1}]

Do[U[0,n]:=1,{n,4,6,1}]

Now fix the boundary conditions.

Do[U[j,0]:=0,{j,1,10}]

Do[U[j,10]:=0,{j,1,10}]

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

t=Table[U[0,n],{n,0,10}]

Set the size of the parameter r.

r=0.1

Enter the algorithm to compute the j+1st value of U in terms of the jth.

Do[Do[U[j+1,n]=(1-2 r) U[j,n]+r (U[j,n+1]+U[j,n-1]),{n,1,9,1}],{j,0,9,1}]

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

t3=Table[U[3,n],{n,0,10}]

ListPlot[t3,Joined->True]

Check and plot the value at n=10.

t10=Table[U[10,n],{n,0,10}]

ListPlot[t10,Joined->True]