Large matrix Inverse.

Started by
5 comments, last by aggieblue92 10 years ago

Hello, i need help in implementing large matrix decomposition.
i will be using a 9 by 9 matrix.

i am using directxMath as my matrix manipulation/calculation class, but it operates only with 4x4 Matrices.

Any chance anyone has a simple solution for this? or at least simplified implementation.

I did not really understand the Gauss-Jordan method. i found an example with a 3x3 matrix, but i could not really get my head around how to implement it on a bigger matrix...

Then there is a method Inverse of a Matrix using Minors, Cofactors and Adjugate, which looked like a nightmare.
Any help appreciated , thanks!

Advertisement

I've not used it, but IIRC, eigen implements matrices of any size.

I second Hodgman's advice of using eigen. I've used it for finite element methods which use huge matrices and It's a great tool for those kinds of problems. However, if you really want to implement your own matrix factorization techniques, look into using things like LU decomposition, QR decomposition, Cholesky decomposition, or singular value decomposition. There are many techniques out there to solve matrix problems, but usually it's helpful to know what kinds of problems you want to solve or what kinds of matrices you will encounter so you can pick the appropriate technique.

I think the main thing is to realize that, odds are, you're doing something that someone's probably written a better, faster library for. If you want to do it just to learn the factorization techniques, by all means try it out.

For Gaussian Elimination I found a teaching I appreciated in Essential Mathematics by Van Verth. They also provide source code for an implementation for general N by N matrices in C++. Gauss-Jordan is just a small extension to Gaussian Elimination where you augment the identity and run elimination: http://en.wikipedia.org/wiki/Gaussian_elimination#Finding_the_inverse_of_a_matrix

As mentioned by others there are other ways to solve larger matrix problems which may be computationally more efficient than just brute force Gaussian Elimination.

There's not just the efficiency at stake here, but the accuracy of the result, which really depends on the matrix itself. Without knowing any specifics about the matrix you're trying to invert or the problem that generates the matrix, you'll have to watch out for ill-conditioned matrices (where the condition number is high). You might have implemented a method like Gaussian elimination correctly, but the result is still garbage because the matrix itself is bad, so you might need a more accurate method.

Speaking to efficiency, Gaussian elimination isn't the fastest method for inverting a matrix. If you're trying to do this for a game, LU decomposition is probably a good starting point.

Do you really need a matrix inverse function? Most numerical linear algebra problems can be solved without explicitly computing the inverse.

LU decomposition is probably the most efficient way, but it is not as numerically stable as a QR matrix inversion, which is backwards-stable. I would avoid gaussian elimination because it is less stable.

Gauss-Jordan elimination is nice and runs in O(n^2) time, but implementation can be tricky with row exchanges and all, plus it's only somewhat parallel programming friendly, if you're tapping into GPU resources.

This topic is closed to new replies.

Advertisement