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 code allows for memory allocation which can be in excess of the actual minimum required size for a given matrix; this facilitates repetitive multiple calculations on matrices of differing sizes (without having to release/reallocate memory for each change in size.)

The code includes two files:

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

Back to Mike Dinolfo's welcome screen