How to find determinant of large matrix

后端 未结 5 1025
抹茶落季
抹茶落季 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:17

    I assume you're using the naive method of expanding Laplace's formula. If you want to gain in speed, you can decompose your matrix M using LU decomposition (into two lower- and upper-diagonal matrices) which you can achieve with a modified Gauss-Jordan elimination in 2*n^3/3 FLOPS and then calculate the determinant as:

    det(M) = det(L) * det(U), which for triangular matrices is just the product of the entries in their diagonal.

    This process will still be faster than O(n!).

    Edit: you can also use Crout's method, which is widely implemented.

提交回复
热议问题