function mtx_A = mtx_generate_2DLaplacian(n)
%
% Generate the matrix A in the project_2009
%
% mtx_A1      = 4*eye(n);
% mtx_A1(2,1) = -1;
% for ii=2:n-1
%     mtx_A1(ii-1,ii) = -1;
%     mtx_A1(ii+1,ii) = -1;
% end
% mtx_A1(n-1,n)    = -1;

i_idx = zeros(3*n-2,1);
j_idx = zeros(3*n-2,1);
val   = zeros(3*n-2,1);

i_idx(1:n,1) = 1:n;
j_idx(1:n,1) = 1:n;
val(1:n,1)   = 4 * ones(n,1);

i_idx(n+1:2*n-1,1) = 1:n-1;
j_idx(n+1:2*n-1,1) = 2:n;
val(n+1:2*n-1,1)   = -ones(n-1,1);

i_idx(2*n:3*n-2,1) = 2:n;
j_idx(2*n:3*n-2,1) = 1:n-1;
val(2*n:3*n-2,1)   = -ones(n-1,1);

m        = ( 3 * n - 2 ) * n + 2 * ( n - 1 ) * n;
m2       = 3 * n - 2;
i_idx_A  = zeros(m,1);
j_idx_A  = zeros(m,1);
val_A    = zeros(m,1);

for ii = 1:n
    i_idx_A((ii-1)*m2+1:ii*m2,1) = i_idx + ( ii - 1 ) * n;
    j_idx_A((ii-1)*m2+1:ii*m2,1) = j_idx + ( ii - 1 ) * n;
    val_A((ii-1)*m2+1:ii*m2,1)   = val;
end

i_idx_A(m2*n+1:m2*n+(n-1)*n,1) = 1:(n-1)*n;
j_idx_A(m2*n+1:m2*n+(n-1)*n,1) = n+1:n*n;
val_A(m2*n+1:m2*n+(n-1)*n,1)   = -ones((n-1)*n,1);
i_idx_A(m2*n+(n-1)*n+1:m,1)    = n+1:n*n;
j_idx_A(m2*n+(n-1)*n+1:m,1)    = 1:(n-1)*n;
val_A(m2*n+(n-1)*n+1:m,1)      = -ones((n-1)*n,1);

mtx_A = sparse(i_idx_A, j_idx_A, val_A); 
