EDIT. Since this question was asked, I got a PhD on solving linear system of equations for tomography. As this question still gets a lot of traffic, I want to stress out the first sentence from the answer by @sellibitze: There is not simple answer. It highly depends on the nature of the matrix, and almost always you don't wan't to invert the matrix.
Now, to the original question by this very innocent man who thinks this can be answered easily...
While googleing about matrix inversion algorithms I found that there are several ways (and opinions!) about how to do this in code. I wondered which method is the fastest, or the one with the best performance, and trying to found that answer I found nothing.
I know that for some cases a pseudo-inverse can be computed (using SVD, cholevsky,...), I actually use some of those in my code, and I know that several times an inverse just doesn't exist, etc. It is easy to find an specific answer for an specific problem but not a general intuition for this big (HUGE!) problem that is matrix inversion.
So my question is:
What method is best in performance for small matrices? And in precision? What about big matrices?
My personal case is a 6x6 (EDIT:symetric) matrix that have to be inverted thousands of times (yes,yes, with different values) and I need high precision, but for sure speed would come really handy.
Note that I am not looking for code, I will code myself whatever answer fits most to my case, but I think this is a question that lots of programmers would like to know.
just swap the 'a' and 'd', negate the 'b' and 'c', then divide all by the determinant ad−bc. That's really the most straightforward 'trick', just memorize that pattern.
We can find the matrix inverse only for square matrices, whose number of rows and columns are equal such as 2 × 2, 3 × 3, etc. In simple words, inverse matrix is obtained by dividing the adjugate of the given matrix by the determinant of the given matrix.
There is not simple answer. Make sure that you've read and understood this article.
For 2x2 matrices computing the inverse can be done with a simple formular involving the determinant. But for anything larger I would prefer factorizations, for example a pivoted LU factorization. If you're concerned about performance and deal with large sparse matrices, an iterative solver might be appropriate. Alternativly you can try MUMPS (multifrontal massivly parallel solver) and measure the performance. The problem with iterative solvers is that their speed of convergence heavily depends on the condition of the inverse problem and whether you find good preconditioners.
Perhaps you should start with the Eigen library and try pivoted LU factorizations first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With