% Script TrySparse % use the gallery to produce Poisson matrices of different sizes and show % that they are sparse as n increases. Show percentage of nonzero entries % for increasing n disp(' ') disp(' Sparsity of Poisson matrix for increasing size ') disp(' n All Nonzero Fraction') for n = 2:2:30 A = gallery('poisson',n); % result is n^2 by n^2 all = n^2*n^2; nonzero = sum(sum(full(A)~=0)); frac = nonzero/all; disp(sprintf(' %3.0f %6.0f %6.0f %7.5f',n^2,all,nonzero,frac)) end