public boolean decompose ( DMatrixRMaj mat , int indexStart , int n ) { double m [ ] = mat . data ; double el_ii ; double div_el_ii = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { double sum = m [ indexStart + i * mat . numCols + j ] ; int iEl = i * n ; int jEl = j * n ; int end = iEl + i ; // k = 0:i-1 for ( ; iEl < end ; iEl ++ , jEl ++ ) { // sum -= el[i*n+k]*el[j*n+k]; sum -= el [ iEl ] * el [ jEl ] ; } if ( i == j ) { // is it positive-definate? if ( sum <= 0.0 ) return false ; el_ii = Math . sqrt ( sum ) ; el [ i * n + i ] = el_ii ; m [ indexStart + i * mat . numCols + i ] = el_ii ; div_el_ii = 1.0 / el_ii ; } else { double v = sum * div_el_ii ; el [ j * n + i ] = v ; m [ indexStart + j * mat . numCols + i ] = v ; } } } return true ; }
Decomposes a submatrix . The results are written to the submatrix and to its internal matrix L .