% % This script will demonstrate some of the % % Unsymetric sparse matrix capabilities of Matlab % % % D.C. Sorensen % Last modified 3 Sep 04 % NZhistory = []; % % read a matrix from matrix market % echo on; % A = mmread('west2021.mtx'); % A = mmread('bfw398a.mtx'); A = mmread('add32.mtx'); % A = mmread('memplus.mtx'); echo off; [n,m] = size(A); disp('order of A ... n ='), disp(n) disp(' ') disp(' Strike a key ') disp(' ') pause norm(A-A',1) disp(' norm(A-A'',1) ') disp(' % Use one or inf norm for sparse A ') disp(' ') disp(' Strike a key ') disp(' ') pause % % -----------------------natural ordering------------------------------------- % spy(A) title('Natural Ordering','Fontsize',15) disp(' spy(A) ') disp(' ') disp(' Strike a key ') disp(' ') pause [L,U,P] = lu(A); spy(L,'r') title('L Factor Fill in Red ','Fontsize',15) hold spy(U,'g') title('U Factor Fill in Green ','Fontsize',15) hold NonzerosLU = nnz(L) + nnz(U) NZhistory = [NZhistory , NonzerosLU]; disp(' ') disp(' Strike a key ') disp(' ') pause % % -----------------------colmmd ordering------------------------------------- % p = colmmd(A); disp(' p = colmmd(A); ') spy(A(:,p)) title('colmmd Ordering','Fontsize',15) disp(' spy(A(:,p)) ') disp(' ') disp(' Strike a key ') disp(' ') pause [L,U] = lu(A(:,p)); spy(L,'r') title('L Factor Fill in Red ','Fontsize',15) hold spy(U,'g') title('U Factor Fill in Green ','Fontsize',15) hold NonzerosLU = nnz(L) + nnz(U) NZhistory = [NZhistory , NonzerosLU]; disp(' ') disp(' Strike a key ') disp(' ') pause % % -----------------------colmmd ordering with L U P Q Umfpack------------------------- % p = colmmd(A); disp(' p = colmmd(A); ') spy(A(:,p)) title('colmmd Ordering','Fontsize',15) disp(' spy(A(:,p)) ') disp(' ') disp(' Strike a key ') disp(' ') pause [L,U,P,Q] = lu(A(:,p)); spy(L,'r') title('L Factor Fill in Red ','Fontsize',15) hold spy(U,'g') title('U Factor Fill in Green ','Fontsize',15) hold disp(' UMfpack with colmmd ordering ') NonzerosLU = nnz(L) + nnz(U) NZhistory = [NZhistory , NonzerosLU]; disp(' ') disp(' Strike a key ') disp(' ') pause % % -----------------------natural ordering with L U P Q Umfpack------------------------- % [L,U,P,Q] = lu(A); spy(L,'r') title('L Factor Fill in Red ','Fontsize',15) hold spy(U,'g') title('U Factor Fill in Green ','Fontsize',15) hold disp(' UMfpack with natural ordering ') NonzerosLU = nnz(L) + nnz(U) NZhistory = [NZhistory , NonzerosLU]; disp(' ') disp(' Strike a key ') disp(' ') pause % % -----------------------colmmd ordering with L U threshold------------------------- % thresh = .1; p = colmmd(A); disp(' p = colmmd(A); ') [L,U,P] = lu(A(:,p),thresh); spy(L,'r') title('L Factor Fill in Red ','Fontsize',15) hold spy(U,'g') title('U Factor Fill in Green ','Fontsize',15) hold disp(sprintf(' Threshold pivoting, thresh = %d',thresh)) NonzerosLU = nnz(L) + nnz(U) NZhistory = [NZhistory , NonzerosLU]; disp(' ') disp(' Strike a key ') disp(' ') pause % % -----------------------colmmd ordering with Umfpack threshold------------------------- % thresh = .1; p = colmmd(A); disp(' p = colmmd(A); ') [L,U,P,Q] = lu(A(:,p),thresh); spy(L,'r') title('L Factor Fill in Red ','Fontsize',15) hold spy(U,'g') title('U Factor Fill in Green ','Fontsize',15) hold disp(sprintf(' UMF with Threshold pivoting, thresh = %d',thresh)) NonzerosLU = nnz(L) + nnz(U) NZhistory = [NZhistory , NonzerosLU]; disp(' ') disp(' Strike a key ') disp(' ') pause % % Display a comparision of fill in for various methods % bar(NZhistory,.2) xlabel(' natural mindeg UMFpack thresh UMF thresh ','Fontsize',20) ylabel(' Nonzeros in L','fontsize',20)