function [A] = Laplacian_mat(m, varargin) % Square matrix if nargin < 2 n = m; else % Rectangular matrix arg1 = varargin{1}; n = arg1(1); end; % Create a partial Laplacian for one "row" of the grid % approximation (Doesn't work for grid widths less than two) z = sparse(zeros(1,n)); z(1) = 4; z(2) = -1; tridiag=kron(speye(m), toeplitz(z)); % Now generate the cell prototype for the offdiagonal elements z = sparse(zeros(1,m)); z(2) = -1; offdiag = toeplitz(z); %create the discrete Laplacian A=tridiag + kron(offdiag, speye(n));