www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/SparseLaplacianOperatorMatrixExample.m

    %% Sparse Laplacian Operator Matrix
% This example visualizes a sparse Laplacian operator matrix.
%%
% The matrix representation of the discrete Laplacian operator on a
% two-dimensional, |n|-by- |n| grid is a |n*n|-by- |n*n| sparse matrix.
% There are at most five nonzero elements in each row or column. You can
% generate the matrix as the Kronecker product of one-dimensional
% difference operators. In this example |n = 5|.

% Copyright 2015 The MathWorks, Inc.

n = 5;
I = speye(n,n);
E = sparse(2:n,1:n-1,1,n,n);
D = E+E'-2*I;
A = kron(D,I)+kron(I,D);
%%
% Visualize the sparsity pattern with |spy|.
spy(A,'k')