private static function getCofactors(Matrix $matrix)
    {
        $cofactors = self::getMinors($matrix);
        $dimensions = $matrix->rows;

        $cof = 1;
        for ($i = 0; $i < $dimensions; ++$i) {
            $cofs = $cof;
            for ($j = 0; $j < $dimensions; ++$j) {
                $cofactors[$i][$j] *= $cofs;
                $cofs = -$cofs;
            }
            $cof = -$cof;
        }

        return new Matrix($cofactors);
    }
private static function getCofactors(Matrix $matrix)
    {
        $cofactors = self::getMinors($matrix);
        $dimensions = $matrix->rows;

        $cof = 1;
        for ($i = 0; $i < $dimensions; ++$i) {
            $cofs = $cof;
            for ($j = 0; $j < $dimensions; ++$j) {
                $cofactors[$i][$j] *= $cofs;
                $cofs = -$cofs;
            }
            $cof = -$cof;
        }

        return new Matrix($cofactors);
    }
private static function getCofactors ( Matrix $ matrix ) { $ cofactors = self :: getMinors ( $ matrix ) ; $ dimensions = $ matrix -> rows ; $ cof = 1 ; for ( $ i = 0 ; $ i < $ dimensions ; ++ $ i ) { $ cofs = $ cof ; for ( $ j = 0 ; $ j < $ dimensions ; ++ $ j ) { $ cofactors [ $ i ] [ $ j ] *= $ cofs ; $ cofs = - $ cofs ; } $ cof = - $ cof ; } return new Matrix ( $ cofactors ) ; }
Calculate the cofactors of the matrix

@param Matrix $matrix The matrix whose cofactors we wish to calculate
@return Matrix
Calculate the cofactors of the matrix