EricDarve / numerical_linear_algebra

Julia code for the book Numerical Linear Algebra
114 stars 41 forks source link

Julia indexing on p. 334 #178

Closed shaundatta closed 4 years ago

shaundatta commented 4 years ago

The code for Lx=b (L sparse, b dense) loops for k=A.rowptr[i]:A.rowptr[i+1]-2. Perhaps I am mistaken, but I would expect this to be k=A.rowptr[i]:A.rowptr[i+1]-1, as it is in the code for matrix-vector multiplication on p. 332, where we select the indices of nzval corresponding to each row of the matrix.

EricDarve commented 4 years ago

The last entry is indeed A.rowptr[i+1]-1 however this corresponds to the diagonal entry. So it is used in the division two lines down. That's basically the main difference between a mat-vec and a triangular solve. You need to skip the diagonal entry and use it to divide.