sparse_test 13-Apr-2014 10:06:00 SPARSE_TEST MATLAB version Test MATLAB's sparse matrix features. SPARSE_TEST01: Demonstrate the use of MATLAB's SPARSE facility 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: Demonstrate the use of MATLAB's SPARSE facility 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: Demonstrate the use of MATLAB's SIZE, NNZ and FIND commands 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: Demonstrate the use of MATLAB's SPARSE facility to set or increment a matrix one entry at a time. I J New A(I,J) 8 3 1 8 10 1 9 1 1 4 4 1 7 6 1 8 4 1 3 1 1 8 3 2 4 6 1 3 7 1 5 2 1 8 2 1 3 3 1 6 1 1 5 2 2 2 8 1 3 7 2 10 5 1 7 8 1 5 7 1 2 10 1 2 3 1 8 5 1 8 4 2 3 1 2 7 5 1 5 7 2 1 4 1 8 7 1 2 2 1 1 1 1 5 7 3 8 6 1 2 7 1 2 2 2 1 2 1 2 2 3 4 4 2 3 3 2 9 8 1 6 2 1 3 1 3 10 8 1 6 4 1 2 7 2 10 2 1 3 4 1 1 7 1 5 10 1 5 7 4 Number of nonzero entries is 36 Sum of entries is 50.000000 Matrix printed in sparse triplet form: a = (1,1) 1 (3,1) 3 (6,1) 1 (9,1) 1 (1,2) 1 (2,2) 3 (5,2) 2 (6,2) 1 (8,2) 1 (10,2) 1 (2,3) 1 (3,3) 2 (8,3) 2 (1,4) 1 (3,4) 1 (4,4) 2 (6,4) 1 (8,4) 2 (7,5) 1 (8,5) 1 (10,5) 1 (4,6) 1 (7,6) 1 (8,6) 1 (1,7) 1 (2,7) 2 (3,7) 2 (5,7) 4 (8,7) 1 (2,8) 1 (7,8) 1 (9,8) 1 (10,8) 1 (2,10) 1 (5,10) 1 (8,10) 1 Matrix printed in usual full matrix form: ans = 1 1 0 1 0 0 1 0 0 0 0 3 1 0 0 0 2 1 0 1 3 0 2 1 0 0 2 0 0 0 0 0 0 2 0 1 0 0 0 0 0 2 0 0 0 0 4 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 1 2 2 1 1 1 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 1 0 0 SPARSE_TEST05: Create the 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.127521 seconds Sparse storage matrix required 0.626385 seconds Number of nonzeros is 1 Zero out all entries greater than 2000000 Full storage matrix required 0.032899 seconds Sparse storage matrix required 0.397375 seconds Number of nonzeros is 2000000 Zero out all entries greater than 3999999 Full storage matrix required 0.014321 seconds Sparse storage matrix required 0.056261 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.052503 seconds Sparse storage matrix required 0.636401 seconds Using sparse triplet required 0.115079 seconds Number of nonzeros is 1 Zero out all entries greater than 2000000 Full storage matrix required 0.032902 seconds Sparse storage matrix required 0.308767 seconds Using sparse triplet required 0.335824 seconds Number of nonzeros is 2000000 Zero out all entries greater than 3999999 Full storage matrix required 0.014151 seconds Sparse storage matrix required 0.055787 seconds Using sparse triplet required 0.565589 seconds Number of nonzeros is 3999999 SPARSE_TEST Normal end of execution. 13-Apr-2014 10:06:07 diary off