%% LU Factorization of Sparse Matrix
% Compute the LU factorization of a sparse matrix and verify the identity L*U = P*S*Q.
%
% Create a 60-by-60 sparse adjacency matrix of the connectivity graph of the Buckminster-Fuller geodesic dome.

S = bucky;

%
% Compute the LU factorization of S using the sparse matrix syntax with four outputs to return the row and column permutation matrices.

[L,U,P,Q] = lu(S);

%
% Permute the rows and columns of S with P*S*Q and compare the result with multiplying the triangular factors L*U. The 1-norm of their difference is within roundoff error, indicating that L*U = P*S*Q.

e = P*S*Q - L*U;
norm(e,1)

% Copyright 2018 The MathWorks, Inc.