I found some C++ code for finding the determinant of matrix, for 4×4 to 8×8. It works ok, but my project needs matrices that are 18×18 or more, and the code is too slow. The code is recursive, but is recursion the right concept to deal with an 18×18 matrix? How else can I find the determinant?
Share
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
Musing LU decomposition (into two lower- and upper-diagonal matrices) which you can achieve with a modified Gauss-Jordan elimination in2*n^3/3 FLOPSand 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.