Problem 2

The A of this problem is simply obtained by taking m=5 in probl. 1:
m=5;n=m-1;N=n^2;
maind=4*ones(N,1);
neardiag=rem(1:N-1,n)~=0;
neardiag=-neardiag;
fardiag=-ones(N-n,1);

A=...
diag(maind)+...
diag(neardiag,1) +...
diag(neardiag,-1) + ...
diag(fardiag,n) +...
diag(fardiag,-n) ;

Assemble the RHS (according to hints)

left=[20,40,60,80];top=[50,20,10,0];bot=zeros(1,4),right=left

m=5;n=m-1;

B=[bot;[left(2:n-1)' zeros(n-2,n-2) right(2:n-1)'];top]
B(1,1)=bot(1)+left(1);B(1,n)=bot(n)+right(1);
B(n,1)=left(n)+top(1);B(n,n)=top(n)+right(n);
B=B';B=B(:)

Solve the linear system

Tvek=A\B
T=reshape(Tvek,n,n)'
T=flipud(T)
T=[fliplr(left)' T fliplr(right)']

Append boundaries

NW=0.5*(left(n)+top(1));NE=0.5*(top(n)+right(n));
SE=0.5*(bot(n)+right(1));SW=0.5*(bot(1)+left(1));
T=[NW top NE;
   T;
   SW bot SE]
Let's check:
for i=2:m; for j=2:m ;
  tt(i,j)= 4*T(i,j)-T(i-1,j)-T(i+1,j)-T(i,j-1)-T(i,j+1);
end; end
There's a function for this:
del2(T)

Visualize

 surf(T) 
 xlabel('x')
 ylabel('y')
 zlabel('z')