inverse of a matrix

how should i write a prog to get an inverse of a matrix
it comes in what area of c++
Hi rahulmm,

there are several ways of doing this. But the first question is, what kind of representation you have?

One way of doing this is to use the gaussian elimination on the matrix. That way you got an complexity with O(n^3) in a fairly easy way.

If you already have a way to calculate the determinant of a matrix (which you proberbly could use to test if a matrix even is invertible; Not all are! But gaussian does the test too..) you can use the equation

A^-1 = det(A)^-1 * adj(A)
Then you may check validity and compare performance with LAPACK library. Matrix inverse goes by two steps there:
1. LU factorization - GETRF
2. Inverse of LU-factorized matrix - GETRI

Of course, whether inverse is correct might be checked on a small matrix "by hands".
Hi!

here is a link where the invertion algorithm is well explained:

http://www.wikihow.com/Inverse-a-3X3-Matrix

Hope it help,

IIRC the inverse of a matrix is an unstable operation with many caveats when implementing it. I'm guessing that if you need the inverse you might also need more matrix operations and thats why i'd advise you to use a library. If on the other hand the sole purpose is to practice creating this operation then follow the links above.
To RedX ..
what is the name of the library that can be used in our program for matrix operation ?
I'm not very familiar with matrix libraries but lapak http://www.netlib.org/lapack/ supports some matrices.

Then there's http://sourceforge.net/apps/wordpress/itpp/ but not sure how well it handles matrices but it certainly has support for them. It also uses syntax very similar to MATLAB when creating and manipulating data.
Topic archived. No new replies allowed.