www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/EigenvaluesUsingFunctionHandleExample.m
%% Eigenvalues Using Function Handle % Create a 1500-by-1500 random sparse matrix with a 25% approximate density % of nonzero elements. n = 1500; A = sprand(n,n,0.25); %% % Find the LU factorization of the matrix, returning a permutation vector % |p| that satisfies |A(p,:) = L*U|. [L,U,p] = lu(A,'vector'); %% % Create a function handle |Afun| that accepts a vector input |x| and uses % the results of the LU decomposition to, in effect, return |A\x|. Afun = @(x) U\(L\(x(p))); %% % Calculate the six smallest magnitude eigenvalues using |eigs| with the % function handle |Afun|. The second input is the size of |A|. d = eigs(Afun,1500,6,'sm')