%% Difference Between 'smallestabs' and 'smallestreal' Eigenvalues
% Create a symmetric positive definite sparse matrix.

A = delsq(numgrid('C', 150));

%
% Compute the six smallest real eigenvalues using 'smallestreal', which employs a Krylov method using A.

tic
d = eigs(A, 6, 'smallestreal')
toc

%
% Compute the same eigenvalues using 'smallestabs', which employs a Krylov method using the inverse of A.

tic
dsm = eigs(A, 6, 'smallestabs')
toc

% The eigenvalues are clustered near zero. The 'smallestreal' computation struggles to converge using A since the gap between the eigenvalues is so small. Conversely, the 'smallestabs' option uses the inverse of A, and therefore the inverse of the eigenvalues of A, which have a much larger gap and are therefore easier to compute. This improved performance comes at the cost of factorizing A, which is not necessary with 'smallestreal'.
% Copyright 2012 The MathWorks, Inc.