//========================================================================================= bool Matrix::AssignCofactorTo( int row, int col, Scalar& cofactor ) const { Matrix subMatrix; if( !subMatrix.AssignSubMatrix( row, col, *this ) ) return false; if( !subMatrix.AssignDeterminantTo( cofactor ) ) return false; if( ( row + col ) % 2 == 1 ) cofactor = cofactor * -1.0; return true; }
//========================================================================================= bool Matrix::AssignInverse( const Matrix& matrix, InverseType inverseType, InverseResult& inverseResult ) { // TODO: Calculate left and right inverse matrices for non-square matrices. inverseResult = NONSINGULAR_MATRIX; Scalar scalar; if( !matrix.AssignDeterminantTo( scalar ) ) return false; if( scalar == 0.0 ) { inverseResult = SINGULAR_MATRIX; return true; } if( !scalar.Invert() ) return false; if( matrix.rows == 1 && matrix.cols == 1 ) { if( !AssignDimensions( 1, 1 ) ) return false; if( !AssignScalarFrom( 0, 0, scalar ) ) return false; } else if( matrix.rows == matrix.cols ) { if( !AssignAdjugate( matrix ) ) return false; if( !Scale( scalar ) ) return false; } else if( matrix.rows > matrix.cols ) return false; // TODO: Deal with this case. else if( matrix.rows < matrix.cols ) return false; // TODO: Deal with this case. return true; }