Skip to content

Commit

Permalink
REF: scale by smallest non-zero element
Browse files Browse the repository at this point in the history
Since we're technically manipulating a linear system, it seems that the property of the final result remaining the same despite scaling applies. If scaling by the inverse of the smallest element, the matrix error becomes relative to the magnitudes of the numbers rather than an absolute quantity.

This intuition seems true because all of the tests pass
  • Loading branch information
Aweptimum committed Nov 9, 2023
1 parent 3ec7c55 commit f386771
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/LinearAlgebra/Reduction/RowEchelonForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@ public static function gaussianElimination(NumericMatrix $A): array
$swaps = 0;
$ε = $A->getError();

// Scale the matrix by its smallest non-zero element
$min = PHP_INT_MAX;
for ($i = 0; $i < $m; $i++) {
for ($j = 0; $j < $n; $j++) {
$elem = \abs($A[$i][$j]);
if (Support::isNotZero($elem, $ε) and $elem < $min) {
$min = $elem;
}
}
}

$R = $A->scalarMultiply(1/$min)->getMatrix();

for ($k = 0; $k < $size; $k++) {
// Find column max
$i_max = $k;
Expand Down

0 comments on commit f386771

Please sign in to comment.