/* cmatinv.cpp -- inverse of complex 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. Only simple pivoting used. * * Replaces input matrix with its inverse. */ int cmatinv(complex **a,int n) { complex **inv,tmp,*t; int i,j,k,retval; retval = 0; inv = new complex *[n]; for (i=0;i [n]; } // Initialize identity matrix 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