08-Jan-2022 09:46:49 sparse_test(): MATLAB/Octave version 9.8.0.1380330 (R2020a) Update 2 Test sparse(): sparse_test01(): Use sparse() to define a tiny sparse matrix. a = (1,1) 11 (3,1) 31 (1,2) 12 (2,2) 22 (2,3) 23 (3,3) 33 (3,4) 34 (1,5) 15 (3,5) 35 sparse_test02(): Use sparse() to define a sparse matrix, and solve an associated linear system. ans = 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000 10.0000 11.0000 12.0000 13.0000 14.0000 15.0000 16.0000 17.0000 18.0000 19.0000 20.0000 21.0000 22.0000 23.0000 24.0000 25.0000 26.0000 27.0000 28.0000 29.0000 30.0000 31.0000 32.0000 33.0000 34.0000 35.0000 36.0000 37.0000 38.0000 39.0000 40.0000 41.0000 42.0000 43.0000 44.0000 45.0000 46.0000 47.0000 48.0000 49.0000 50.0000 51.0000 52.0000 53.0000 54.0000 55.0000 56.0000 57.0000 58.0000 59.0000 60.0000 61.0000 62.0000 63.0000 64.0000 65.0000 66.0000 67.0000 68.0000 69.0000 70.0000 71.0000 72.0000 73.0000 74.0000 75.0000 76.0000 77.0000 78.0000 79.0000 80.0000 81.0000 82.0000 83.0000 84.0000 85.0000 86.0000 87.0000 88.0000 89.0000 90.0000 91.0000 92.0000 93.0000 94.0000 95.0000 96.0000 97.0000 98.0000 99.0000 100.0000 sparse_test03(): Use size(), nnz(), and find to retrieve information about a sparse matrix. [ m, n ] = size ( A ) Matrix rows M = 21 Matrix columns N = 21 nz_num = nnz ( A ) Matrix nonzeros NZ_NUM = 60 [ row, col, val ] = find ( A ) Matrix sparse triplet representation: ROW COL VAL 1 1 10.000000 2 1 1.000000 1 2 1.000000 2 2 9.000000 3 2 1.000000 2 3 1.000000 3 3 8.000000 4 3 1.000000 3 4 1.000000 ..(skipping some entries)... 18 18 7.000000 19 18 1.000000 18 19 1.000000 19 19 8.000000 20 19 1.000000 19 20 1.000000 20 20 9.000000 21 20 1.000000 20 21 1.000000 21 21 10.000000 sparse_test04(): Use sparse() to set or increment a matrix one entry at a time. I J New A(I,J) 9 10 1 2 10 1 7 1 1 3 6 1 10 10 1 2 10 2 10 5 1 9 2 1 5 10 1 8 10 1 7 1 2 9 10 2 7 8 1 8 4 1 7 2 1 8 1 1 3 1 1 1 9 1 7 4 1 10 1 1 5 4 1 8 8 1 2 5 1 5 7 1 8 8 2 3 7 1 7 2 2 2 5 2 10 4 1 6 3 1 8 3 1 6 7 1 9 10 3 6 2 1 2 3 1 9 3 1 9 3 2 10 4 2 2 3 2 7 5 1 4 9 1 6 6 1 10 3 1 8 8 3 4 6 1 1 1 1 6 8 1 10 2 1 6 5 1 1 4 1 Number of nonzero entries is 39 Sum of entries is 50.000000 Matrix printed in sparse triplet form: a = (1,1) 1 (3,1) 1 (7,1) 2 (8,1) 1 (10,1) 1 (6,2) 1 (7,2) 2 (9,2) 1 (10,2) 1 (2,3) 2 (6,3) 1 (8,3) 1 (9,3) 2 (10,3) 1 (1,4) 1 (5,4) 1 (7,4) 1 (8,4) 1 (10,4) 2 (2,5) 2 (6,5) 1 (7,5) 1 (10,5) 1 (3,6) 1 (4,6) 1 (6,6) 1 (3,7) 1 (5,7) 1 (6,7) 1 (6,8) 1 (7,8) 1 (8,8) 3 (1,9) 1 (4,9) 1 (2,10) 2 (5,10) 1 (8,10) 1 (9,10) 3 (10,10) 1 Matrix printed in usual full matrix form: ans = 1 0 0 1 0 0 0 0 1 0 0 0 2 0 2 0 0 0 0 2 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 1 0 0 1 0 1 1 0 1 1 1 1 0 0 2 2 0 1 1 0 0 1 0 0 1 0 1 1 0 0 0 3 0 1 0 1 2 0 0 0 0 0 0 3 1 1 1 2 1 0 0 0 0 1 sparse_test05(): Use spdiags(), speye(), kron() to create a sparse matrix associated with the Poisson equation on an N by N grid. Number of nonzeros is 460 sparse_test06(): Zero out a portion of a matrix. Compare the time required when using full or sparse storage. The sparse matrix takes longer to modify, and it takes longer when there are more elements to remove. Matrix is of size 2000 by 2000 Initial number of nonzeros is 4000000 Zero out all entries greater than 1 Full storage matrix required 0.019085 seconds Sparse storage matrix required 0.290723 seconds Number of nonzeros is 1 Zero out all entries greater than 2000000 Full storage matrix required 0.009714 seconds Sparse storage matrix required 0.156212 seconds Number of nonzeros is 2000000 Zero out all entries greater than 3999999 Full storage matrix required 0.003342 seconds Sparse storage matrix required 0.009514 seconds Number of nonzeros is 3999999 sparse_test07(): Zero out some elements of a sparse matrix. Compare the time required when using full storage, sparse storage, sparse storage with the sparse triplet representation. Matrix is of size 2000 by 2000 Initial number of nonzeros is 4000000 Zero out all entries greater than 1 Full storage matrix required 0.010404 seconds Sparse storage matrix required 0.290163 seconds Using sparse triplet required 0.028836 seconds Number of nonzeros is 1 Zero out all entries greater than 2000000 Full storage matrix required 0.009689 seconds Sparse storage matrix required 0.161562 seconds Using sparse triplet required 0.087566 seconds Number of nonzeros is 2000000 Zero out all entries greater than 3999999 Full storage matrix required 0.003348 seconds Sparse storage matrix required 0.009256 seconds Using sparse triplet required 0.121683 seconds Number of nonzeros is 3999999 sparse_test(): Normal end of execution. 08-Jan-2022 09:46:51