Looking for some code (in C++) which can be used to invert a "large" matrix? Maybe this will help. This code (actually a template for a generic matrix class) provides for "fast" matrix inversion. To be sure, there are some restrictions:

- the matrix must be square, with non-zero determinant (i.e., it must be invertible)
- the matrix must have non-zero terms in the diagonal
- there's no pivoting of rows or columns, hence, accuracy might not be adequate for your needs.

The code includes two files:

- a header file with the actual meat and potatoes; this is probably all that you will need to include in your application code
- a test program {with a main()} which creates a randomly filled matrix of 200 x 200 "double" variables, inverts the matrix, computes the product of the original matrix times its inverse, and displays the difference between the product and the "desired" identity matrix.

This code does not perform any error checking; you'll have to add exception handling or whatever to suit your own tastes. But it does do the matrix inversion via LU factorization: if "n" is the number of rows (equivalent to number of columns), then this results in execution times proportional to n³, rather than the n! which is attained with Gauss elimination. Also, because the code is written as a template, you can instantiate a matrix with complex elements (e.g., if electronic circuit design is your thing.)

Performance? Well, time to invert the "test" 200 x 200 matrix is about 3 seconds, on a 233 Mhz Pentium running Windows 95 with an .exe file created via the DJGPP compiler. Incidentally, I **highly** recommend this compiler; you can get it (for free!) at http://www.delorie.com.

Download the C++ matrix inversion template (matrix.zip; 3 Kb) here