private void reducedRowEchelonForm ( int method ) { final int rows = coeff . length ; final int cols = coeff [ 0 ] . length ; int k = - 1 ; // denotes current position on diagonal int pivotRow ; // row index of pivot element int pivotCol ; // column index of pivot element double pivot ; // value of pivot element // main loop, transformation to reduced row echelon form boolean exitLoop = false ; while ( ! exitLoop ) { k ++ ; // pivot search for entry in remaining matrix // (depends on chosen method in switch) // store position in pivotRow, pivotCol // TODO: Note that we're using "row, col", whereas "col, row" would be // more common? IntIntPair pivotPos = new IntIntPair ( 0 , 0 ) ; IntIntPair currPos = new IntIntPair ( k , k ) ; switch ( method ) { case TRIVAL_PIVOT_SEARCH : pivotPos = nonZeroPivotSearch ( k ) ; break ; case TOTAL_PIVOT_SEARCH : pivotPos = totalPivotSearch ( k ) ; break ; } pivotRow = pivotPos . first ; pivotCol = pivotPos . second ; pivot = coeff [ this . row [ pivotRow ] ] [ col [ pivotCol ] ] ; if ( LOG . isDebugging ( ) ) { StringBuilder msg = new StringBuilder ( ) ; msg . append ( "equations " ) . append ( equationsToString ( 4 ) ) ; msg . append ( " *** pivot at (" ) . append ( pivotRow ) . append ( ' ' ) . append ( pivotCol ) . append ( ") = " ) . append ( pivot ) . append ( ' ' ) ; LOG . debugFine ( msg . toString ( ) ) ; } // permute rows and columns to get this entry onto // the diagonal permutePivot ( pivotPos , currPos ) ; // test conditions for exiting loop // after this iteration // reasons are: Math.abs(pivot) == 0 if ( ( Math . abs ( pivot ) <= DELTA ) ) { exitLoop = true ; } // pivoting only if Math.abs(pivot) > 0 // and k <= m - 1 if ( ( Math . abs ( pivot ) > DELTA ) ) { rank ++ ; pivotOperation ( k ) ; } // test conditions for exiting loop // after this iteration // reasons are: k == rows-1 : no more rows // k == cols-1 : no more columns if ( k == rows - 1 || k == cols - 1 ) { exitLoop = true ; } } // end while reducedRowEchelonForm = true ; }
Brings this linear equation system into reduced row echelon form with choice of pivot method .