function try_lu (A, method, issym) % sparse LU factorization of A % % MATLAB Primer, 6th Edition % Kermit Sigmon and Timothy A. Davis % Section 13.4, page 72. figure (1) clf reset subplot (2, 2, 1) spy (A) title ('Original matrix A') t = cputime ; if (nargin > 2) S = spones (A) + spones (A') ; p = feval (method, S) ; A = A (p,p) ; elseif (nargin > 1) q = feval (method, A) ; A = A (:,q) ; end torder = cputime - t subplot (2, 2, 2) spy (A) title ('Permuted matrix A') t = cputime ; [L, U, P] = lu (A) ; tlu = cputime - t total = torder + tlu subplot (2, 2, 3) spy (L+U) title ('LU factors') normest (L*U-P*A) Lnz = full (sum (spones (L))) - 1 ; Unz = full (sum (spones (U')))' - 1 ; flop_count = 2*Lnz*Unz + sum (Lnz) subplot (2, 2, 4) S = spones (A) ; etreeplot (S'*S) title ('column elimination tree')