MathPHP\LinearAlgebra\Matrix::cofactor PHP Method

cofactor() public method

Cᵢⱼ = (-1)ⁱ⁺ʲMᵢⱼ Example: [1 4 7] If A = [3 0 5] [1 9 11] [1 4 -] [1 4] Then M₁₂ = det [- - -] = det [1 9] = 13 [1 9 -] Therefore C₁₂ = (-1)¹⁺²(13) = -13 https://en.wikipedia.org/wiki/Minor_(linear_algebra)
public cofactor ( integer $mᵢ, integer $nⱼ ) : number
$mᵢ integer Row to exclude
$nⱼ integer Column to exclude
return number
    public function cofactor(int $mᵢ, int $nⱼ)
    {
        if (!$this->isSquare()) {
            throw new Exception\MatrixException('Matrix is not square; cannot get cofactor of a non-square matrix');
        }
        if ($mᵢ >= $this->m || $mᵢ < 0) {
            throw new Exception\MatrixException('Row to exclude for cofactor does not exist');
        }
        if ($nⱼ >= $this->n || $nⱼ < 0) {
            throw new Exception\MatrixException('Column to exclude for cofactor does not exist');
        }
        $Mᵢⱼ = $this->minor($mᵢ, $nⱼ);
        $⟮−1⟯ⁱ⁺ʲ = (-1) ** ($mᵢ + $nⱼ);
        return $⟮−1⟯ⁱ⁺ʲ * $Mᵢⱼ;
    }