www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/SingularValueDecompositionOfSparseMatrixExample.m
%% Singular Value Decomposition of Sparse Matrix % |west0479| is a real-valued 479-by-479 sparse matrix. The matrix has a % few large singular values, and many small singular values. % % Load |west0479| and store it as |A|. load west0479 A = west0479; %% % Compute the singular value decomposition of |A|, returning the six % largest singular values and the corresponding singular vectors. Specify a % fourth output argument to check convergence of the singular values. [U,S,V,cflag] = svds(A); cflag %% % |cflag| indicates that all of the singular values converged. The singular % values are on the diagonal of the output matrix |S|. s = diag(S) %% % Check the results by computing the full singular value decomposition of % |A|. Convert |A| to a full matrix and use |svd|. [U1,S1,V1] = svd(full(A)); %% % Plot all of the singular values of |A| using a logarithmic scale. semilogy(diag(S1),'r.') title('Singular Values of west0479')