%
% Compute k^2 x k^2 matrix and rhs arising from the 5-point
% finite difference discretization in k x k grid
% of Poisson or Helmholtz
% equation in unit square with boundary condition u=0.
%
%  [A,b]=matrix5p(k):
%
%   -Delta(u)=1    (Poisson)
% 
%  [A,b]=matrix5p(k,ome):
%
%   -Delta(u)-ome*u=1   (Helmholtz)
%
%  A is symmetric, and if ome <=0 it is pos.def. too !
%
function [A,b]=matrix5p(k,varargin)
if length(varargin)==1
    ome = varargin{1};
else
    ome = 0.0;
end
n = k*k;
h = 1.0/(k+1);
h2 = h*h;
I = speye(k,k);
E = sparse(2:k,1:k-1,1,k,k);
D = E+E'-2*I;
A = (-kron(D,I)-kron(I,D))/h2-ome*speye(n,n);
b = ones(n,1);
