%% Density of Sparse Matrix
% The density of a matrix is the ratio of nonzeros to the total number of elements, nnz(X)/numel(X).
% Create a sparse matrix representing the finite difference Laplacian on an L-shaped domain and calculate its density.

X = delsq(numgrid('L',20));
spy(X)

%

d = nnz(X)/numel(X)

% The result indicates that only about 2% of the elements in the matrix are nonzero.
% Copyright 2018 The MathWorks, Inc.