improve matrix inverse

This commit is contained in:
Arkadiusz Kondas 2016-04-30 23:47:35 +02:00
parent f7b91bea72
commit 2952557028

View File

@ -225,12 +225,8 @@ class Matrix
$newMatrix = array(); $newMatrix = array();
for ($i = 0; $i < $this->rows; ++$i) { for ($i = 0; $i < $this->rows; ++$i) {
for ($j = 0; $j < $this->columns; ++$j) { for ($j = 0; $j < $this->columns; ++$j) {
$subMatrix = $this->crossOut($i, $j); $minor = $this->crossOut($i, $j)->getDeterminant();
if (fmod($i + $j, 2) == 0) { $newMatrix[$i][$j] = fmod($i + $j, 2) == 0 ? $minor : -$minor;
$newMatrix[$i][$j] = ($subMatrix->getDeterminant());
} else {
$newMatrix[$i][$j] = -($subMatrix->getDeterminant());
}
} }
} }