Ad

We know that a matrix is a set of complex or real number arranged according to a rectangular array,but wo only dscuss real number here.When wo do some operations on a matrix, wo ofent need to get the dterminant value of the matrix, and we need a function to calculate the determinant value of the matrix.
The definitions of matrices and related terms are not well explained here. The specific contents are shown in linear algebra. Here, only a few concepts are briefly described.

1, Algebraic cofactor matrix:
In the n order determinant, the elements int the R row and the C column of an element are deleted, and the n - 1 order determinant composed of the remaining elements which do not change the original order is called the cofactor of the element Ecof[R,C].And it is called algebraic cofactor Eacof[R,C] if the resulting cofactor is multiplied by the R + C power of -1.

For example:

Matrix A =

         |1  9  3|              
         |4  8  6|            
         |7  8  5|

Cofactor Ecof[1,2] of A =

                     |4  6|  
                     |7  5|              

Algebraic cofactor Eacof[1,2] of A =

                               (-1)^(r+c) * Ecof[1,2] = -1 * |4  6|
                                                             |7  5|

2, The determinant of value of a matrix:
The determinant of an n * n matrix is equal to the sum of the product of the element of any row(or column) and the corresponding algebraic cofactor. In particular, for a matrix of order 2 * 2, its deterimant is the product of the two values of the left diagonal(the value of the upper left corner and the value of the lower right corner) minus the product of the two values of the right diagonal (the value of the lower left corner and the value of the upper right corner).

For example:

Matrix A =

         |1  9  3| 
         |4  8  6|
         |7  8  5|

Determinant(A) =

                Eacof[1,1] + Eacof[2,1] + Eacof[3,1]

Here, there will be a Matrix class, your purpose is to achieve the
determinant value of the matrix.
Note:There's already a function that return a matrix of cofactors(note that is a not an algebraic cofactor)

//We have Matrix Matrix::GetCofactorMatrix() to return cofactor matrix
//double & Matrix::GetElement(int _Row, int _Col) to return _Row and _Col of double element of matrix


double Matrix::GetValueOfDeterminant()
{
    if((2 == MaxRow) && (2 == MaxCol))
    {
        return GetElement(1,1) * GetElement(2,2) - GetElement(1,2) * GetElement(2,1);
    }
    else
    {
        double ResultValue = 0;
        for(int c = 1; c <= MaxCol; c++)
        {
            int PowOfNegativeOne = std::pow(-1, c);
            ResultValue += GetCofactorMatrix(1,c).GetValueOfDeterminant() * GetElement(1,c) * PowOfNegativeOne;
        }
        return ResultValue;  
    }
    
}