improve matrix inverse

This commit is contained in:
Arkadiusz Kondas 2016-04-30 23:47:35 +02:00
parent f7b91bea72
commit 2952557028
1 changed files with 3 additions and 7 deletions

View File

@ -53,7 +53,7 @@ class Matrix
/**
* @param array $array
*
*
* @return Matrix
*/
public static function fromFlatArray(array $array)
@ -225,12 +225,8 @@ class Matrix
$newMatrix = array();
for ($i = 0; $i < $this->rows; ++$i) {
for ($j = 0; $j < $this->columns; ++$j) {
$subMatrix = $this->crossOut($i, $j);
if (fmod($i + $j, 2) == 0) {
$newMatrix[$i][$j] = ($subMatrix->getDeterminant());
} else {
$newMatrix[$i][$j] = -($subMatrix->getDeterminant());
}
$minor = $this->crossOut($i, $j)->getDeterminant();
$newMatrix[$i][$j] = fmod($i + $j, 2) == 0 ? $minor : -$minor;
}
}