MCordingley\LinearAlgebra\Matrix::determinant PHP Метод

determinant() публичный Метод

public determinant ( ) : float
Результат float
    public function determinant() : float
    {
        $this->checkSquare();
        try {
            $decomp = new LUP($this);
        } catch (MatrixException $exception) {
            // Singular matrix, so determinant is defined to be zero.
            return 0.0;
        }
        $upper = $decomp->upper();
        $determinant = 1.0;
        for ($i = 0, $size = $upper->getRowCount(); $i < $size; $i++) {
            $determinant *= $upper->get($i, $i);
        }
        $sign = $decomp->parity() % 2 ? -1 : 1;
        return $sign * $determinant;
    }

Usage Example

Пример #1
0
 public function testSingularDeterminant()
 {
     $matrix = new Matrix([[0, 1], [0, 1]]);
     static::assertEquals(0, $matrix->determinant());
 }