Sparse Arrays(1/35) 令a形 a=2*eye(10) a= 2 0 0 0 00 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 A sparse matrix is a large matrix in which the vast majority of the elements are zero. @日济大学 AW TONGJIUNIVERSITY
Sparse Arrays(1/35) a=2*eye(10) a = 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 A sparse matrix is a large matrix in which the vast majority of the elements are zero
Sparse Arrays(2/35) 令a b= 1 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 00 0 0 0 0 0 1 00 00 00 00 00 10 000 0 0 0 0 001 If these two matrices are multiplied together: c=a*b CPHAW @月协大学 TONGJI UNIVERSITY
Sparse Arrays(2/35) b = 1 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 If these two matrices are multiplied together: c=a*b
Sparse Arrays(3/35) C= 2 000 00 0000 0 40 0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 10 0 00 0 0 00 00 0 2 0000 00 00 0 02000 0 00 0 0 002 00 0 000000020 00000 00002 The process of multiplying these two sparse matrices together requires 1900 multiplications and additions But the nonzero elements calculateonly 190 times---1/10 of the whole calculation @日济大学 AW TONGJIUNIVE具sITY
Sparse Arrays(3/35) C= 2 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 2 ✓ The process of multiplying these two sparse matrices together requires multiplications and additions. ✓ But the nonzero elements calculate only 190 times --- 1/10 of the whole calculation. 1900
Sparse Arrays(4/35) ▣The sparse data type The sparse data type actually saves three values for each nonzero element:the value of the element and the row and column numbers where the element is located. A=eye(2); sparse(A) ans= (1,1) 1 (2,2) 1 CDHAW @月协大学 TONGJI UNIVERSITY
Sparse Arrays(4/35) The sparse data type ✓ The sparse data type actually saves three values for each nonzero element: the value of the element and the row and column numbers where the element is located. ✓ A=eye(2); sparse(A) ans = (1,1) 1 (2,2) 1
Sparse Arrays(5/35) Common Matlab sparse matrix functions Category Function Description speye Create a sparse identity matrix Create Create a matrix containing uniformly sprand sparse distributed random values. matrices Create a matrix containing normally sprandn distributed random values. Full-to- sparse Convert a full matrix into a sparse matrix. sparse full Convert a sparse matrix into a full matrix. conversion functions find Find indices and values of nonzero elements in a matrix. 同濟大学 AW TONGJI UNIVERSITY
Sparse Arrays(5/35) Common Matlab sparse matrix functions Category Function Description Create sparse matrices speye Create a sparse identity matrix sprand Create a matrix containing uniformly distributed randomvalues. sprandn Create a matrix containing normally distributed randomvalues. Full-tosparse conversion functions sparse Convert a full matrix into a sparse matrix. full Convert a sparse matrix into a full matrix. find Find indices and values of nonzero elements in a matrix