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

    %% Eigenvalues and Singular Values of Sparse Matrix

% Copyright 2015 The MathWorks, Inc.


%% Section 1
% This example shows how to find the smallest eigenvalue and eigenvector of
% a sparse matrix.

%%
% Set up the five-point Laplacian difference operator on a 65-by-65 grid in
% an _L_-shaped, two-dimensional domain.
L = numgrid('L',65);
A = delsq(L);

%%
% Determine the order and number of nonzero elements.
size(A)
nnz(A)

%%
% |A| is a matrix of order 2945 with 14,473 nonzero elements.

%%
% Compute the smallest eigenvalue and eigenvector.
[v,d] = eigs(A,1,0);

%%
% Distribute the components of the eigenvector over the appropriate grid
% points and produce a contour plot of the result.
L(L>0) = full(v(L(L>0)));
x = -1:1/32:1;
contour(x,x,L,15)
axis square