1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63:
<?php
namespace Chippyash\Math\Matrix\Transformation\Strategy\Invert;
use Chippyash\Matrix\Transformation\Cofactor;
use Chippyash\Matrix\Transformation\Transpose;
use Chippyash\Math\Matrix\Computation\Div\Scalar;
use Chippyash\Math\Matrix\NumericMatrix;
use Chippyash\Math\Matrix\Derivative\Determinant as Det;
use Chippyash\Math\Matrix\Interfaces\InversionStrategyInterface;
use Chippyash\Math\Matrix\Traits\CreateCorrectMatrixType;
class Determinant implements InversionStrategyInterface
{
use CreateCorrectMatrixType;
public function invert(NumericMatrix $mA)
{
$rows = $mA->rows();
$cols = $mA->columns();
$work = array();
$fDet = new Det();
$fCof = new Cofactor();
for ($row = 0; $row < $rows; $row++) {
for ($col = 0; $col < $cols; $col++) {
$t = $fDet($fCof($mA,[$row + 1, $col + 1]));
if (fmod($row + $col, 2) == 0) {
$work[$row][$col] = $t;
} else {
$work[$row][$col] = $t->negate();
}
$r = $row + 1;
$c = $col + 1;
}
}
$fTr = new Transpose();
$fDiv = new Scalar();
return $fTr($fDiv($this->createCorrectMatrixType($mA, $work), $fDet($mA)));
}
}