Q-learning/mat.cpp
// LU decomposition IN PLACE
// Uses simple Dolittle Algorithm
// Returns the permuation of the rows
LU decomposition IN PLACE
Uses simple Dolittle Algorithm
Returns the permuation of the rows
LU decomposition IN PLACE Uses simple Dolittle Algorithm Returns the permuation of the rows
int *Matrix::LU()
{
    int *perm;
    assertDefined("LU decomposition");
    perm = new int(maxr);
    for (int r=0; r<maxr; r++) perm[r] = r;
    for (int r=0; r<maxr; r++) {
        for (int rr=r+1; rr<maxr; rr++) {
            double l;
            if (m[r][r]==0) {
                for (int j=r+1; j<maxr; j++) {
                    if (m[j][r]!=0) {
                        int tmp;
                        swapRows(r, j);
                        tmp = perm[r]; perm[r] = perm[j]; perm[j] = tmp;
                        break;
                    }
                }
            }
            l = m[rr][r]/m[r][r];
            for (int c=r; c<maxc; c++) {
                m[rr][c] -= l * m[r][c];
            }
            m[rr][r] = l;
        }
    }
    for (int r=0; r<maxr; r++) printf("%d\n", perm[r]);
    return perm;
}
int * Matrix :: LU ( ) { int * perm ; assertDefined ( " " ) ; perm = new int ( maxr ) ; for ( int r = 0 ; r < maxr ; r ++ ) perm [ r ] = r ; for ( int r = 0 ; r < maxr ; r ++ ) { for ( int rr = r + 1 ; rr < maxr ; rr ++ ) { double l ; if ( m [ r ] [ r ] == 0 ) { for ( int j = r + 1 ; j < maxr ; j ++ ) { if ( m [ j ] [ r ] != 0 ) { int tmp ; swapRows ( r , j ) ; tmp = perm [ r ] ; perm [ r ] = perm [ j ] ; perm [ j ] = tmp ; break ; } } } l = m [ rr ] [ r ] / m [ r ] [ r ] ; for ( int c = r ; c < maxc ; c ++ ) { m [ rr ] [ c ] -= l * m [ r ] [ c ] ; } m [ rr ] [ r ] = l ; } } for ( int r = 0 ; r < maxr ; r ++ ) printf ( " \n " , perm [ r ] ) ; return perm ; }
LU decomposition IN PLACE
Uses simple Dolittle Algorithm
Returns the permuation of the rows
LU decomposition IN PLACE Uses simple Dolittle Algorithm Returns the permuation of the rows