function sparse_perm3()
%
% Generate a sparse test matrix
%
n=50; B=ones(n,3); B(:,2)=5; B(:,3)=-1;
A=spdiags(B,[-1 0 3],n,n); A(n-4:n,1:5)=-6; 
%
% Compare different column permutations available in Matlab.
% Note that for numerical stability, rows need to be permuted too
%
subplot(3,3,1); 
spy(A); title('Original matrix')
[L,U,P]=lu(A);
subplot(3,3,2)
spy(L); title('triag factors L')
subplot(3,3,3)
spy(U); title('triang factors U')
subplot(3,3,4); 
p=colamd(A);
spy(A(:,p)); title('Cols permuted by colamd')
[L,U,P]=lu(A(:,p));
subplot(3,3,5)
spy(L)
subplot(3,3,6)
spy(U)
[L,U,p,q]=lu(A,'vector');
subplot(3,3,7); 
spy(A(:,q)); title('Cols permuted by UMFPACK')
subplot(3,3,8)
spy(L)
subplot(3,3,9)
spy(U)
