public static double recursive( DMatrixRMaj mat )
    {
        if(mat.numRows == 1) {
            return mat.get(0);
        } else if(mat.numRows == 2) {
            return mat.get(0) * mat.get(3) - mat.get(1) * mat.get(2);
        } else if( mat.numRows == 3 ) {
            return UnrolledDeterminantFromMinor_DDRM.det3(mat);
        }

        double result = 0;

        for(int i = 0; i < mat.numRows; i++) {
            DMatrixRMaj minorMat = new DMatrixRMaj(mat.numRows-1,mat.numRows-1);

            for(int j = 1; j < mat.numRows; j++) {
                for(int k = 0; k < mat.numRows; k++) {

                    if(k < i) {
                        minorMat.set(j-1,k,mat.get(j,k));
                    } else if(k > i) {
                        minorMat.set(j-1,k-1,mat.get(j,k));
                    }
                }
            }

            if( i % 2 == 0 )
                result += mat.get(0,i) * recursive(minorMat);
            else
                result -= mat.get(0,i) * recursive(minorMat);

        }

        return result;
    }
public static double recursive ( DMatrixRMaj mat ) { if ( mat . numRows == 1 ) { return mat . get ( 0 ) ; } else if ( mat . numRows == 2 ) { return mat . get ( 0 ) * mat . get ( 3 ) - mat . get ( 1 ) * mat . get ( 2 ) ; } else if ( mat . numRows == 3 ) { return UnrolledDeterminantFromMinor_DDRM . det3 ( mat ) ; } double result = 0 ; for ( int i = 0 ; i < mat . numRows ; i ++ ) { DMatrixRMaj minorMat = new DMatrixRMaj ( mat . numRows - 1 , mat . numRows - 1 ) ; for ( int j = 1 ; j < mat . numRows ; j ++ ) { for ( int k = 0 ; k < mat . numRows ; k ++ ) { if ( k < i ) { minorMat . set ( j - 1 , k , mat . get ( j , k ) ) ; } else if ( k > i ) { minorMat . set ( j - 1 , k - 1 , mat . get ( j , k ) ) ; } } } if ( i % 2 == 0 ) result += mat . get ( 0 , i ) * recursive ( minorMat ) ; else result -= mat . get ( 0 , i ) * recursive ( minorMat ) ; } return result ; }
<p>
A simple and inefficient algorithm for computing the determinant. This should never be used.
It is at least two orders of magnitude slower than {@link DeterminantFromMinor_DDRM}. This is included
to provide a point of comparison for other algorithms.
</p>
@param mat The matrix that the determinant is to be computed from
@return The determinant.