Subsection 8.5.1 Additional homework
ΒΆHomework 8.5.1.1.
When using iterative methods, the matrices are typically very sparse. The question then is how to store a sparse matrix and how to perform a matrix-vector multiplication with it. One popular way is known as compressed row storage that involves three arrays:
- 1D array - nzA(nonzero A) which stores the nonzero elements of matrix \(A \text{.}\) In this array, first all nonzero elements of the first row are stored, then the second row, etc. It has size- nnzeroes(number of nonzeroes).
- 1D array - irwhich is an integer array of size \(n + 1 \) such that- ir( 1 )equals the index in array- nzAwhere the first element of the first row is stored.- ir( 2 )then gives the index where the first element of the second row is stored, and so forth.- ir( n+1 )equals- nnzeroes + 1. Having this entry is convenient when you implement a matrix-vector multiplication with array- nzA.
- 1D array - icof size- nnzeroeswhich holds the column indices of the corresponding elements in array- nzA.
- Write a function - [ nzA, ir, ic ] = Create_Poisson_problem_nzA( N ) that creates the matrix \(A \) in this sparse format.
- Write a function - y = SparseMvMult( nzA, ir, ic, x ) that computes \(y = A x \) with the matrix \(A \) stored in the sparse format.
