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 sizennzeroes(number of nonzeroes).1D array
irwhich is an integer array of size \(n + 1 \) such thatir( 1 )equals the index in arraynzAwhere 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 )equalsnnzeroes + 1. Having this entry is convenient when you implement a matrix-vector multiplication with arraynzA.1D array
icof sizennzeroeswhich holds the column indices of the corresponding elements in arraynzA.
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.
