Let\'s see how long it takes to solve a sparse matrix equation when the matrix i
ID: 3799699 • Letter: L
Question
Let's see how long it takes to solve a sparse matrix equation when the matrix is banded. The matrix can be random, so spdiags can be used since we don't care exactly how the columns of B are inserted into the matrix. For example, a sparse, random, tridiagonal matrix can be easily generated by n = .....; B = rand(n, 3); S = spdiags(B, [-1:1], n, n); a) Time a tridiagonal matrix. (i) Time a pentadiagonal matrix, but again it only has three nonzero diagonals. That is, the -2, 0, and +2 diagonals are nonzero. (ii) Time a matrix which again only has three nonzero diagonals, but now they are the -4, 0, and +4 diagonals.Explanation / Answer
S = sparse(A)example
S = sparse(m,n)example
S = sparse(i,j,v)example
S = sparse(i,j,v,m,n)example
S = sparse(i,j,v,m,n,nz)example
Description
example
S = distributed(A) converts a full matrix into sparse type by squeeze out any zero components. If a matrix contains several zeros, changing the matrix to distributed storage saves memory.
example
S = sparse(m,n) generates associate m-by-n all zero distributed matrix.
example
S = sparse(i,j,v) generates a distributed matrix S from the triplets i, j, and v such S(i(k),j(k)) = v(k). The max(i)-by-max(j) output matrix has area assigned for length(v) nonzero components. distributed adds along components in v that have duplicate subscripts in i and j.
If the inputs i, j, and v area unit vectors or matrices, they need to have an equivalent variety of components. as an alternative, the argument v and/or one among the arguments i or j will be scalars.
example
S = sparse(i,j,v,m,n) specifies the dimensions of S as m-by-n.
example
S = sparse(i,j,v,m,n,nz) allocates area for nz nonzero components. Use this syntax to portion additional area for nonzero values to be stuffed in when construction.
Examples
collapse all
Open Script
Save Memory victimization distributed Storage
Create a ten,000-by-10,000 full storage unit matrix.
A = eye(10000);
whos A
Name Size Bytes category Attributes
A 10000x10000 800000000 double
This matrix uses 800-megabytes of memory.
Convert the matrix to distributed storage.
S = sparse(A);
whos S
Name Size Bytes category Attributes
S 10000x10000 240008 double distributed
In distributed type, an equivalent matrix uses roughly zero.25-megabytes of memory. during this case, you'll be able to avoid full storage fully by victimization the speye operate, that creates distributed identity matrices directly.
Sparse Matrix of All Zeros
Open Script
S = sparse(10000,5000)
S =
All zero sparse: 10000×5000
Sparse Matrix of Nonzeros with such Size
Open Script
Create a 1500-by-1500 distributed matrix from the triplets i, j, and v.
i = [900 1000];
j = [900 1000];
v = [10 100];
S = sparse(i,j,v,1500,1500)
S =
(900,900) ten
(1000,1000) one hundred
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.