public DenseMatrix inverse ( ) { int m = lu . nrows ( ) ; int n = lu . ncols ( ) ; if ( m != n ) { throw new IllegalArgumentException ( String . format ( "Matrix is not square: %d x %d" , m , n ) ) ; } DenseMatrix inv = Matrix . zeros ( n , n ) ; for ( int i = 0 ; i < n ; i ++ ) { inv . set ( i , piv [ i ] , 1.0 ) ; } solve ( inv ) ; return inv ; }
Returns the matrix inverse . For pseudo inverse use QRDecomposition .