LU Decomposition from Numerical Recipes not working; what am I doing wrong?

后端 未结 4 2089
小鲜肉
小鲜肉 2021-01-13 23:01

I\'ve literally copied and pasted from the supplied source code for Numerical Recipes for C for in-place LU Matrix Decomposition, problem is its not working.

I\'m s

4条回答
  •  臣服心动
    2021-01-13 23:21

    The thing that looks most suspicious to me is the part marked "search for largest pivot". This does not only search but it also changes the matrix A. I find it hard to believe that is correct.

    The different version of the LU algorithm differ in pivoting, so make sure you understand that. You cannot compare the results of different algorithms. A better check is to see whether L times U equals your original matrix, or a permutation thereof if your algorithm does pivoting. That being said, your result is wrong because the determinant is wrong (pivoting does not change the determinant, except for the sign).

    Apart from that @Philip has good advice. If you want to understand the code, start by understanding LU decomposition without pivoting.

提交回复
热议问题