src/Matrix/n_matrix.cc
// Input		A     : Input normal matrix (this)
// Return		Ainv  : Inverse of input A
// Note			      : A is unaltered in this routine
// Note			      : Assumes A is square!
// sosi: 6/23/92 - THIS STILL HAS TROUBLE FLAGGING A SINGULAR MATRIX
//	           FOR EXAMPLE TRY matrix(10,10,5.0);
Input          A     : Input normal matrix (this)
Return         Ainv  : Inverse of input A
Note                         : A is unaltered in this routine
Note                         : Assumes A is square.
Input A : Input normal matrix ( this ) Return Ainv : Inverse of input A Note : A is unaltered in this routine Note : Assumes A is square .
_matrix* n_matrix::xinv()
  {
  complex z(0,0);
  int nr = rows();			
  n_matrix* Ainv = new n_matrix(nr,nr); 
  int* indx;
  indx = new int[cols()];
  n_matrix ALU(*this);			
  ALU.LU_decomp(indx);			
  n_matrix Ii(nr, 1, z);		
  n_matrix Ainvi(nr, 1, z);		
  int i=0, j=0;
  for(i=0; i<nr; i++)			
    {					
    Ii.data[i] = 1;			
    Ainvi = Ii; 			
    ALU.LU_backsub(indx, Ainvi);	
    for(j=0; j<nr; j++)			
      (*Ainv)(j,i) = Ainvi.data[j];
    Ii.data[i] = 0;			
    }
  delete [] indx;
  return Ainv;				
  }
_matrix * n_matrix :: xinv ( ) { complex z ( 0 , 0 ) ; int nr = rows ( ) ; n_matrix * Ainv = new n_matrix ( nr , nr ) ; int * indx ; indx = new int [ cols ( ) ] ; n_matrix ALU ( * this ) ; ALU . LU_decomp ( indx ) ; n_matrix Ii ( nr , 1 , z ) ; n_matrix Ainvi ( nr , 1 , z ) ; int i = 0 , j = 0 ; for ( i = 0 ; i < nr ; i ++ ) { Ii . data [ i ] = 1 ; Ainvi = Ii ; ALU . LU_backsub ( indx , Ainvi ) ; for ( j = 0 ; j < nr ; j ++ ) ( * Ainv ) ( j , i ) = Ainvi . data [ j ] ; Ii . data [ i ] = 0 ; } delete [ ] indx ; return Ainv ; }
Input          A     : Input normal matrix (this)
Return         Ainv  : Inverse of input A
Note                         : A is unaltered in this routine
Note                         : Assumes A is square!
Input A : Input normal matrix ( this ) Return Ainv : Inverse of input A Note : A is unaltered in this routine Note : Assumes A is square!
// Get dimension of A // Construct matrix for inverse // Copy matrix A for LU decomp // LU Decomposition of A // Column vector |Ii> // Column vector of inverse |Ainvi> // Go through the columns of I,    -1 // |Ii>, solve for the columns of A  . // Form column of I, |Ii> //		           -1  // Get column of Ainv: A|Ai  > = |Ii> // Copy Ainv column to Ainv // Unform column of I, |Ii> // Return Ainv, a new n_matrix