468,497 Members | 1,875 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,497 developers. It's quick & easy.

c++ code for inverse of NXN matrix

I need c++ code for inverse of nxn matrix ,if available please help me
Mar 7 '08 #1
3 7052
sanctus
84
I need c++ code for inverse of nxn matrix ,if available please help me
I do not know if it is exists for general case. For the 2X2 matrix there is the gsl library. If you have matlab you can call matlab to invert the matrix from your c++ code...
Mar 7 '08 #2
JosAH
11,448 Expert 8TB
Never invert a square matric explicitly: it is highly numerically unstable. A much
better method is to find two triangular matrixes L and U (lower and upper triangular
respectively where L has just ones (1) on its diagonal such that L.U == P.A
where P is a row permutation matrix, Given L, U and P it is extremely easy
to solve the linear system A.x == b.

P.A.x == P.b (swap the elements in b)
L.U.x == P.b
L.y == P.b (by using a simple backward substitution)
U.x == y (by using a simple forward substitution).

Calculate x for the unit vectors b and voila.

Google for "LUP decomposition" for the gory details.

kind regards,

Jos
Mar 7 '08 #3
hsriat
1,654 Expert 1GB
See if you can convert this PHP code to C++

Regards
Mar 29 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

10 posts views Thread by florian kno | last post: by
6 posts views Thread by greenflame | last post: by
6 posts views Thread by vishnu mahendra | last post: by
1 post views Thread by praneeth | last post: by
1 post views Thread by ravleen bindra | last post: by
reply views Thread by DarrenWeber | last post: by
3 posts views Thread by aaram81 | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.