src/LSLib/LSAux.cc
/* Matrix Inversion *************************************-*-c++-*-
**							 	**
**  This routine is taken from "Numerical Recipies", W.H.Press,	**
**  B.P.Flannery, S.A.Teukolsky, & W.T.Vetterling, Cambridge	**
**  University Press, 1989.  See pages 31 through 38.  The code **
**  has been modified for GAMMA into C++.			**
**							 	**
**  The algorithm takes an input matrix A and intially forms	**
**  the LU decomposition of A' where A' is A with any needed	**
**  row permutations. Then, using the LU decomposition and the	**
**  identity matrix it solves for the inverse of A via back	**
**  substitution.
**								**  
**  The LU decomposition formulates the equation		**
**								**  
**		     	    A = LU				**  
**								**  
**  where L is lower triangular and U is upper triangular.	**
**								**
**  [A11 A12 A13 A14]   [L11  0   0   0 ] [U11 U12 U12 U14]	**
**  |A21 A22 A23 A24]   [L21 L22  0   0 ] [ 0  U22 U23 U24|	**
**  |A31 A32 A33 A34] = [L31 L32 L33  0 ] [ 0   0  U33 U34|	**
**  [A41 A42 A43 A44]   [L41 L42 L43 L44] [ 0   0   0  U44]	**
**								**
**  The inverse of A is then found according to the equation	**
**								**
**		         -1	 -1				**
**		       AA   = LUA   = I				**  
**								**  
**  This is done in a columnwise fashion.  Using subscript i	**
**  to indicate matrix columns, 				**
**								**
**		       -1	 -1				**
**	            A|A  > = LU|A  >  = |I >			**  
**		       i	 i	  i			**  
**								**  
**  Columns of the inverse are found by back substitution.	**
**								**
*****************************************************************/


The algorithm takes an input matrix A and intially forms
the LU decomposition of A' where A' is A with any needed
row permutations. Then, using the LU decomposition and the
identity matrix it solves for the inverse of A via back
substitution.

The LU decomposition formulates the equation

A = LU





The inverse of A is then found according to the equation



This is done in a columnwise fashion.  Using subscript i
to indicate matrix columns.



Columns of the inverse are found by back substitution.
The algorithm takes an input matrix A and intially forms the LU decomposition of A ' where A ' is A with any needed row permutations . Then using the LU decomposition and the identity matrix it solves for the inverse of A via back substitution . The LU decomposition formulates the equation A = LU The inverse of A is then found according to the equation This is done in a columnwise fashion . Using subscript i to indicate matrix columns . Columns of the inverse are found by back substitution .
matrix LU_invert(matrix& A)
  {
  matrix ALU = A;			
  int n = A.rows();			
  int *indx;
  indx = new int[n];
  LU_decomp(ALU, indx);			
  matrix Ii(n,1,0.0), Ainv(n,n,0.0);	
  matrix Ainvi;				
  for(int i=0; i<n; i++)		
    {					
    Ii.put(1.0, i, 0);			
    Ainvi = Ii; 			
    LU_backsub(ALU, indx, Ainvi);	
    Ainv.put_block(0, i, Ainvi);	
    Ii.put(0.0, i, 0);			
    }
  delete [] indx;
  return Ainv;
  }
matrix LU_invert ( matrix & A ) { matrix ALU = A ; int n = A . rows ( ) ; int * indx ; indx = new int [ n ] ; LU_decomp ( ALU , indx ) ; matrix Ii ( n , 1 , 0.0 ) , Ainv ( n , n , 0.0 ) ; matrix Ainvi ; for ( int i = 0 ; i < n ; i ++ ) { Ii . put ( 1.0 , i , 0 ) ; Ainvi = Ii ; LU_backsub ( ALU , indx , Ainvi ) ; Ainv . put_block ( 0 , i , Ainvi ) ; Ii . put ( 0.0 , i , 0 ) ; } delete [ ] indx ; return Ainv ; }
Matrix Inversion *************************************-*-c++
This routine is taken from "Numerical Recipies", W.H.Press,
B.P.Flannery, S.A.Teukolsky, & W.T.Vetterling, Cambridge
University Press, 1989.
Matrix Inversion ************************************* - * - c ++ This routine is taken from " Numerical Recipies " W . H . Press B . P . Flannery S . A . Teukolsky & W . T . Vetterling Cambridge University Press 1989 .
//return Ainv(A.rows(), A.rows(), 0.0); // Input		A     : Input matrix // Return		Ainv  : Inverse of input A // Note			      : Assumes A is , non-singular //				and square // Copy matrix A // Get dimension of A //  int indx[n];				// Set up indexing vector // LU Decomposition of A // Matrix for columns of I, |Ii>       -1 // Matrix for columns of A inverse, |Ai  > // 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> //    Fill column of Ainv //    Unform column of I