Phpml\Math\Matrix::getDeterminant PHP Method

getDeterminant() public method

public getDeterminant ( ) : float | integer
return float | integer
    public function getDeterminant()
    {
        if ($this->determinant) {
            return $this->determinant;
        }
        if (!$this->isSquare()) {
            throw MatrixException::notSquareMatrix();
        }
        return $this->determinant = $this->calculateDeterminant();
    }

Usage Example

Example #1
0
 public function testGetMatrixDeterminant()
 {
     //http://matrix.reshish.com/determinant.php
     $matrix = new Matrix([[3, 3, 3], [4, 2, 1], [5, 6, 7]]);
     $this->assertEquals(-3, $matrix->getDeterminant());
     $matrix = new Matrix([[1, 2, 3, 3, 2, 1], [1 / 2, 5, 6, 7, 1, 1], [3 / 2, 7 / 2, 2, 0, 6, 8], [1, 8, 10, 1, 2, 2], [1 / 4, 4, 1, 0, 2, 3 / 7], [1, 8, 7, 5, 4, 4 / 5]]);
     $this->assertEquals(1116.5035, $matrix->getDeterminant(), '', $delta = 0.0001);
 }