Skip to content

Commit

Permalink
Use multiplication/division intelligently when calculating RREF.
Browse files Browse the repository at this point in the history
Matrix.rref now chooses scale or divide based on the magnitude of the
unscaled leading value. Hopefully should cut down on floating point
error (issue #1), but tests don't seem to be indicating that...
  • Loading branch information
hal7df committed Sep 6, 2017
1 parent afae50a commit 16e60c8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions js/matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,17 @@ function Matrix (h, w, zero) {

//Scale row to get the leading one
var scaleFactor = result.rref.get(i,i);
result.rref._divideRow(i, scaleFactor);
if (augment) result.augment._divideRow(i, scaleFactor);

//Determine whether division or multiplication by inverse
//will preserve the most digits
if (Math.abs(scaleFactor) >= 1) {
result.rref._divideRow(i, scaleFactor);
if (augment) result.augment._divideRow(i, scaleFactor);
} else {
scaleFactor = 1./scaleFactor;
result.rref._scaleRow(i, scaleFactor);
if (augment) result.augment._scaleRow(i, scaleFactor)
}

//Zero out rest of column
for (var row = 0; row < result.rref.rows; ++row) {
Expand Down

0 comments on commit 16e60c8

Please sign in to comment.