# Large matrix Inverse.

This topic is 2021 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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!

##### Share on other sites

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

##### Share on other sites

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.

##### Share on other sites

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.

Edited by Randy Gaul

##### Share on other sites

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.

##### Share on other sites

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.

##### Share on other sites
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.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 9
• 15
• 9
• 11