Matlab Demos in the Week-5 Lecture
Contents
The effects of amd and symamd on Cholesky factorizing a SPD matrix
A = gallery('wathen',50,50);
tic; p = amd(A); toc
tic; s = symamd(A); toc
L = chol(A,'lower');
Lp = chol(A(p,p),'lower');
Ls = chol(A(s,s),'lower');
figure;
subplot(2,3,1); spy(A);
title('Sparsity structure of A');
subplot(2,3,2); spy(A(p,p));
title('Sparsity structure of AMD ordered A');
subplot(2,3,3); spy(A(s,s));
title('Sparsity structure of SYMAMD ordered A');
subplot(2,3,4); spy(L);
title('Sparsity structure of Cholesky factor of A');
subplot(2,3,5); spy(Lp);
title('Sparsity structure of Cholesky factor of AMD ordered A');
subplot(2,3,6); spy(Ls);
title('Sparsity structure of Cholesky factor of AMD ordered A');
set(gcf,'Position',[100 100 1380 700]);
Elapsed time is 0.003610 seconds.
Elapsed time is 0.011802 seconds.
The effect of colamd for LU factorizing a nonsymmetric matrix
load west0479
A = west0479;
p = colamd(A);
figure(2);
subplot(2,2,1), spy(A,4), title('A')
subplot(2,2,2), spy(A(:,p),4), title('A(:,p) with colamd')
subplot(2,2,3), spy(lu(A),4), title('lu(A)')
subplot(2,2,4), spy(lu(A(:,p)),4), title('lu(A(:,p))')
Compare RCM and AMD orderings
B = bucky+4*speye(60);
r = symrcm(B);
p = symamd(B);
R = B(r,r);
S = B(p,p);
figure(3);
subplot(2,2,1), spy(R,4), title('B(r,r)')
subplot(2,2,2), spy(S,4), title('B(s,s)')
subplot(2,2,3), spy(chol(R),4), title('chol(B(r,r))')
subplot(2,2,4), spy(chol(S),4), title('chol(B(s,s))')