www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/CompareSparseMatrixAndLUFactorizationExample.m
%% Compare Sparse Matrix and LU Factorization % The Harwell-Boeing collection of sparse matrices and the MATLAB(R) demos % directory include a test matrix |west0479|. It is % a matrix of order 479 resulting from a model due to Westerberg of % an eight-stage chemical distillation column. The spy plot shows evidence % of the eight stages. The |colamd| ordering scrambles % this structure. % Copyright 2015 The MathWorks, Inc. load west0479 A = west0479; p = colamd(A); figure() subplot(1,2,1), spy(A,4), title('A') subplot(1,2,2), spy(A(:,p),4), title('A(:,p)') %% % Comparing the spy plot of the LU factorization of the original matrix % with that of the reordered matrix shows that minimum degree reduces the % time and storage requirements by better than a factor of 2.8. The nonzero % counts are 15918 and 5920, respectively. figure() subplot(1,2,1), spy(lu(A),4), title('lu(A)') subplot(1,2,2), spy(lu(A(:,p)),4), title('lu(A(:,p))')