mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-26 06:46:45 +00:00
improve matrix inverse
This commit is contained in:
parent
f7b91bea72
commit
2952557028
@ -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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user