%% Smallest Eigenvalue of Sparse Matrix
% 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,'smallestabs');

%
% 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

% Copyright 2015 The MathWorks, Inc.