How to find determinant of large matrix

后端 未结 5 1023
抹茶落季
抹茶落季 2020-12-05 06:00

I found some C++ code for finding the determinant of matrix, for 4x4 to 8x8. It works ok, but my project needs matrices that are 18x18 or more, and the code is too slow. The

5条回答
  •  臣服心动
    2020-12-05 06:27

    Since I can't comment, I wish to add this: the Cholesky decomposition (or its variant, LDLT, L a unit lower triangular matrix and D a diagonal matrix) can be used to verify if a symmetric matrix is positive/negative definite: if it is positive definite, the elements of D are all positive, and the Cholesky decomposition will finish successfully without taking the square root of a negative number. If the matrix is negative definite, the elements of D are all negative, the matrix itself will not have a Cholesky decomposition, but the negative of it would.

    "Calculating the determinant of a triangular matrix is simple: multiply the diagonal elements, as the cofactors of the off-diagonal terms are 0. Using an LU decomposition further simplifies this, as L is a unit, lower triangular matrix, i.e. its diagonal elements are all 1, in most implementations. Therefor, you often only have to calculate the determinant of U."

    • You forgot here to take into account that all practical implementations of Gaussian elimination make use of (partial) pivoting for extra numerical stability; so your description is incomplete; one counts the number of row swaps done during the decomposition phase, and after multiplying together all the diagonal elements of U, this product should be negated if the number of swaps is odd.

    As for code, NR is not free; I suggest taking a look at LAPACK/CLAPACK/LAPACK++ @ http://www.netlib.org/ instead. For reference, I can do no better than point you to "Matrix Computations" by Golub and Van Loan.

提交回复
热议问题