
% Jacobi iteration for Laplace' equation 

% grid on unit square, indices of interior points
n = 32;
t = [0:n]/n; 
ind = [2:n];

% solution with random perturbation
u = t'*t;
u(ind,ind)=u(ind,ind) + (rand(n-1,n-1)-1/2);

% smoothing effect, u <- average of neighbors
for k=0:100;
   u(ind,ind) = (u(ind-1,ind) + u(ind,ind-1) + ... 
      u(ind+1,ind) + u(ind,ind+1))/4;
   if rem(k,10) == 0; 
      surf(u), pause;
   end;
end;

