www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/DifferenceBetweenSaAndSmEigenvaluesExample.m
%% Difference Between |'sa'| and |'sm'| Eigenvalues % Create a symmetric positive definite sparse matrix. A = delsq(numgrid('C', 150)); %% % Compute the six smallest algebraic eigenvalues using |'sa'|, which % employs a Krylov method using |A|. tic d = eigs(A, 6, 'sa') toc %% % Compute the same eigenvalues using |'sm'|, which employs a Krylov method % using the inverse of |A|. tic dsm = eigs(A, 6, 'sm') toc %% % The eigenvalues are clustered near zero. The |'sa'| computation struggles % to converge using |A| since the gap between the eigenvalues is so small. % Conversely, the |'sm'| 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.