Monday, May 24, 2010

How to calculate the inverse of nxn matrix using C/C++?

Does anyone have a C or C++ code that can calculate the inverse of nxn matrix?

How to calculate the inverse of nxn matrix using C/C++?
you can make the calculation with the kramer's rule





Given a 3x3 matrix M:





| A B C |


| |


M = | D E F |


| |


| G H I |





Then the determinant is calculated as follows:





n


---


\ i


det M = / M * submat M * -1


--- 0,i 0,i


i=1


where





submat M defines the matrix composed of all rows and columns of M


ij





excluding row i and column j. submat may be called recursively.


ij


| A B C |


M = | D E F | becomes submat = | E F |


| G H I | 11 | H I |





If the determinant is non-zero then the inverse of the matrix exists.


In this case, the value of each matrix element is defined by:





-1 1 i+j


M = ----- * det submat M * -1


j,i det M i,j


No comments:

Post a Comment