• Create Account

## Large matrix Inverse.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

6 replies to this topic

### #1AlexRus  Members

195
Like
0Likes
Like

Posted 07 April 2014 - 10:16 PM

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!

### #2Hodgman  Moderators

49387
Like
1Likes
Like

Posted 07 April 2014 - 10:21 PM

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

1880
Like
0Likes
Like

Posted 08 April 2014 - 12:32 PM

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.

Edited by cadjunkie, 08 April 2014 - 12:33 PM.

### #4Randy Gaul  Members

2343
Like
0Likes
Like

Posted 09 April 2014 - 12:50 PM

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, 09 April 2014 - 12:56 PM.

1880
Like
0Likes
Like

Posted 10 April 2014 - 01:02 PM

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.

### #6Aressera  Members

2668
Like
2Likes
Like

Posted 10 April 2014 - 07:29 PM

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.

### #7Sessamekesh  Members

184
Like
0Likes
Like

Posted 12 April 2014 - 03:28 AM

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.