function A = heatmat(N)
% A = heatmat(N)
% find matrix A for square plate divided into N^2 smaller squares
% matrix has size M by M with M = (N-1)^2

n = N-1;         % interior grid points are n by n grid
M = n^2;         % number of interior grid points
A = zeros(M,M);  % matrix A is of size M by M

for i=1:n        % for columns 1 to n
  for j=1:n      %   for rows 1 to n
    k = i + n*(j-1);      % k is number of point in row j, column i
    A(k,k) = 1;   
    if i>1
      A(k,k-1) =  -.25;   % k-1 is number of point on the left
    end
    if i<n
      A(k,k+1) =  -.25;   % k+1 is number of point on the right
    end
    if j>1
      A(k,k-n) =  -.25;   % k-n is number of point below
    end
    if j<n
      A(k,k+n) =  -.25;   % k+n is number of point above
    end
  end
end



