4

The following dynamic array contains a non-symmetric n*n matrix (with n <=100):

int **matrix;
matrix = new int*[n];
for (int i = 0; i < n; i++)
    matrix[i] = new int[n];

Is there an extremely easy way to invert it? Ideally I'd only use something from the STL or download a single header file.

3
  • what do you mean by invert? try to give some sample input and output for it
    – Adrian
    Commented Mar 8, 2012 at 14:20
  • I mean find the inverse of: en.wikipedia.org/wiki/Invertible_matrix
    – pockethook
    Commented Mar 8, 2012 at 14:23
  • @Adrian Since he calls this thing an nxn-matrix it seems rather obvious what he means by inversion. Commented Mar 8, 2012 at 14:24

2 Answers 2

10

Using Eigen.

http://eigen.tuxfamily.org/index.php?title=Main_Page

You can map your array to an Eigen matrix and then perform efficient matrix inversion.

You must only include it.

I add that usually if you have to perform your inversion for linear system solving, it's better to use a matrix decomposition based on the properties of the matrix that you can exploit.

http://eigen.tuxfamily.org/dox/TutorialLinearAlgebra.html

3

Not extremely easy but it works: Numerical Recipes in c page 48, using LU decomposition.

2
  • Looks to be an interesting book! Just ordered one, should be a handy reference tool.
    – john
    Commented Oct 4, 2012 at 16:12
  • @john the C part of the book is actually free (but admittedly not very user friendly when browsing)
    – assylias
    Commented Oct 4, 2012 at 16:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.