/* matinv.cpp -- inverse of matrix using Gauss-Jordan elimination. * (C) 2001, C. Bond. All rights reserved. */ #include /* Bare-bones Gauss-Jordan algorithm. Returns '0' on success, '1' if * matrix is singular (zero diagonal). No pivoting used. * * Replaces input matrix with its inverse. */ int matinv(double **a,int n) { double **inv,tmp; int i,j,k,retval; retval = 0; inv = new double *[n]; for (i=0;ik) a[k][j] /= tmp; // Don't bother with previous entries inv[k][j] /= tmp; } for (i=0;ik) a[i][j] -= a[k][j]*tmp; inv[i][j] -= inv[k][j]*tmp; } } } // Copy inverse to source matrix for (i=0;i