function A = laplacian2d_sparse3(k)
% LAPLACIAN2D_SPARSE3 : discrete Laplace operator in 2 dimensions
%
% A = laplacian2d_sparse3(k) returns a k^2-by-k^2 sparse matrix

m = k^2;
A = sparse(m,m);

for x = 1:k
    for y = 1:k
        i = (y-1)*k + x;
        
        if y > 1, A(i-k,i) = -1; end;
        if x > 1, A(i-1,i) = -1; end;
        A(i,i) = 4;
        if x < k, A(i+1,i) = -1; end;
        if y < k, A(i+k,i) = -1; end;
        
    end;
end;

