Off[General::spell1];
Clear[Dirichlet,a00,a10,b00,b10,n,M];
Dirichlet[a00_,a10_,b00_,b10_,n_,M_] :=
Module[{h,i,j,k,a0,a1,b0,b1},  
  Set@@{a0[x_],a00};
  Set@@{a1[x_],a10}; 
  Set@@{b0[y_],b00};
  Set@@{b1[y_],b10};
h = (1 / n)//N;
u = Table[0,{n+1},{n+1}];
  For[i=1,i<=n ,i++,
      u[[i,1]] = a0[(i-1)*h] //N;
      u[[i,n+1 ]] = a1[(i-1)*h] //N;
      u[[1,i]] = b0[(i-1)*h] //N ;
      u[[n+1,i]] = b1[(i-1)*h] //N ];
  Clear[i,j,k];
  For[k=1, k<=M, k++,       
     For[j=2,j<=n,j++, 
        For[i=2,i<=n ,i++,
           u[[i,j]] = (u[[i-1,j]] + u[[i+1,j]] + 
                u[[i,j-1]] + u[[i,j+1]])/4 //N] ] ];
Return[u]; ]; 
On[General::spell1];

Clear[g,a0,a1,b0,b1];
g[x_,y_]:= 4x*y*(x-y)*(x+y);
a0[x_]:= g[x,0]; a1[x_]:= g[x,1]; 
b0[y_]:= g[0,y]; b1[y_]:= g[1,y];

u=Dirichlet[a0[x],a1[x],b0[y],b1[y],10,20];

ListPlot3D[u,  AxesLabel->{"t","x","u"},   
ViewPoint->{3,2,1}]

n=10; 
Error = Max[Abs[Table[ u[[i,j]]-g[(i-1)/n,(j-1)/n] //N, 
                  {i,1,n+1},{j,1,n+1}]]]

Clear[g,a0,a1,b0,b1]; 
g[x_,y_]:= 10^(-4) Sinh[3*Pi*x]*Sin[3*Pi*y];
a0[x_]:= g[x,0]; a1[x_]:= g[x,1]; 
b0[y_]:= g[0,y]; b1[y_]:= g[1,y];

u=Dirichlet[a0[x],a1[x],b0[y],b1[y],15,20];

ListPlot3D[u,  AxesLabel->{"t","x","u"},  
ViewPoint->{1,-2,1}]

n=15; 
Error = Max[Abs[Table[ u[[i,j]]-g[(i-1)/n,(j-1)/n] //N, 
                  {i,1,n+1},{j,1,n+1}]]]