%% Reorder Sparse Matrix Columns
% Reorder a sparse matrix with several methods and compare the fill-in incurred by the LU decomposition of the reordered matrices.
%
% Load the west0479 matrix, which is a real-valued 479-by-479 sparse matrix with both real and complex pairs of conjugate eigenvalues. View the sparsity structure.

load west0479.mat
A = west0479;
spy(A)

%
% Calculate several different permutations of the matrix columns, including the nested dissection ordering.

p1 = dissect(A);
p2 = amd(A);
p3 = symrcm(A);

%
% Compare the sparsity structures of the LU decomposition of A using the different ordering methods. The dissect function produces the reordering that incurs the least amount of fill-in.

subplot(1,2,1)
spy(A)
title('Original Matrix')
subplot(1,2,2)
spy(lu(A))
title('LU Decomposition')

%

figure
subplot(1,2,1)
spy(A(p3,p3))
title('Reverse Cuthill-McKee')
subplot(1,2,2)
spy(lu(A(p3,p3)))
title('LU Decomposition')

%

figure
subplot(1,2,1)
spy(A(p2,p2))
title('Approximate Minimum Degree')
subplot(1,2,2)
spy(lu(A(p2,p2)))
title('LU Decomposition')

%

figure
subplot(1,2,1)
spy(A(p1,p1))
title('Nested Dissection')
subplot(1,2,2)
spy(lu(A(p1,p1)))
title('LU Decomposition')

% Copyright 2012 The MathWorks, Inc.