24-Sep-2022 15:48:08 sparse_test(): MATLAB/Octave version 4.2.2 Test sparse(): sparse_test01(): Use sparse() to define a tiny sparse matrix. a = Compressed Column Sparse (rows = 3, cols = 5, nnz = 9 [60%]) (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.00000 2.00000 3.00000 4.00000 5.00000 6.00000 7.00000 8.00000 9.00000 10.00000 11.00000 12.00000 13.00000 14.00000 15.00000 16.00000 17.00000 18.00000 19.00000 20.00000 21.00000 22.00000 23.00000 24.00000 25.00000 26.00000 27.00000 28.00000 29.00000 30.00000 31.00000 32.00000 33.00000 34.00000 35.00000 36.00000 37.00000 38.00000 39.00000 40.00000 41.00000 42.00000 43.00000 44.00000 45.00000 46.00000 47.00000 48.00000 49.00000 50.00000 51.00000 52.00000 53.00000 54.00000 55.00000 56.00000 57.00000 58.00000 59.00000 60.00000 61.00000 62.00000 63.00000 64.00000 65.00000 66.00000 67.00000 68.00000 69.00000 70.00000 71.00000 72.00000 73.00000 74.00000 75.00000 76.00000 77.00000 78.00000 79.00000 80.00000 81.00000 82.00000 83.00000 84.00000 85.00000 86.00000 87.00000 88.00000 89.00000 90.00000 91.00000 92.00000 93.00000 94.00000 95.00000 96.00000 97.00000 98.00000 99.00000 100.00000 sparse_test03(): Use size(), nnz(), and find() to retrieve information about a sparse matrix. Write the sparse triplet data to a text file. [ 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 triplet data saved as "wilkinson.st" sparse_test04(): Use sparse() to set or increment a matrix one entry at a time. I J New A(I,J) 10 7 1 9 10 1 6 2 1 5 5 1 8 4 1 10 5 1 6 2 2 4 4 1 1 5 1 5 8 1 7 2 1 2 7 1 9 5 1 9 8 1 3 5 1 6 8 1 9 10 2 1 3 1 6 1 1 7 10 1 7 1 1 2 8 1 8 4 2 9 1 1 2 8 2 10 4 1 7 10 2 8 1 1 2 10 1 5 5 2 7 2 2 8 6 1 7 9 1 2 7 2 10 5 2 10 7 2 1 2 1 10 1 1 3 1 1 2 4 1 5 5 3 3 8 1 8 4 3 7 10 3 10 7 3 7 8 1 9 1 2 4 1 1 4 2 1 7 10 4 Number of nonzero entries is 34 Sum of entries is 50.000000 Matrix printed in sparse triplet form: a = Compressed Column Sparse (rows = 10, cols = 10, nnz = 34 [34%]) (3, 1) -> 1 (4, 1) -> 1 (6, 1) -> 1 (7, 1) -> 1 (8, 1) -> 1 (9, 1) -> 2 (10, 1) -> 1 (1, 2) -> 1 (4, 2) -> 1 (6, 2) -> 2 (7, 2) -> 2 (1, 3) -> 1 (2, 4) -> 1 (4, 4) -> 1 (8, 4) -> 3 (10, 4) -> 1 (1, 5) -> 1 (3, 5) -> 1 (5, 5) -> 3 (9, 5) -> 1 (10, 5) -> 2 (8, 6) -> 1 (2, 7) -> 2 (10, 7) -> 3 (2, 8) -> 2 (3, 8) -> 1 (5, 8) -> 1 (6, 8) -> 1 (7, 8) -> 1 (9, 8) -> 1 (7, 9) -> 1 (2, 10) -> 1 (7, 10) -> 4 (9, 10) -> 2 Matrix printed in usual full matrix form: ans = 0 1 1 0 1 0 0 0 0 0 0 0 0 1 0 0 2 2 0 1 1 0 0 0 1 0 0 1 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 3 0 0 1 0 0 1 2 0 0 0 0 0 1 0 0 1 2 0 0 0 0 0 1 1 4 1 0 0 3 0 1 0 0 0 0 2 0 0 0 1 0 0 1 0 2 1 0 0 1 2 0 3 0 0 0 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.00808001 seconds Sparse storage matrix required 0.224288 seconds Number of nonzeros is 1 Zero out all entries greater than 2000000 Full storage matrix required 0.00895095 seconds Sparse storage matrix required 0.135187 seconds Number of nonzeros is 2000000 Zero out all entries greater than 3999999 Full storage matrix required 0.00787807 seconds Sparse storage matrix required 0.0296791 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.008111 seconds Sparse storage matrix required 0.219662 seconds Using sparse triplet required 0.0551701 seconds Number of nonzeros is 1 Zero out all entries greater than 2000000 Full storage matrix required 0.00894809 seconds Sparse storage matrix required 0.132393 seconds Using sparse triplet required 0.0953732 seconds Number of nonzeros is 2000000 Zero out all entries greater than 3999999 Full storage matrix required 0.00771284 seconds Sparse storage matrix required 0.0266271 seconds Using sparse triplet required 0.144017 seconds Number of nonzeros is 3999999 sparse_test(): Normal end of execution. 24-Sep-2022 15:48:09