Skip to content

Commit

Permalink
fix: Matrix inverse not working #5
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinRa committed Nov 3, 2021
1 parent c0b2270 commit c5d2256
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 3 additions & 5 deletions _includes/_math/utils/generate_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// hide
td.hidden = true;
} else if (td.set === undefined) { // already created?
td.innerHTML = `<input type=\"number\" style="width: 50px;" value="">`;
td.innerHTML = `<input type=\"text\" style="width: 50px;" value="">`;
td.set = true;
} else if (td.hidden) {
td.hidden = false;
Expand Down Expand Up @@ -52,10 +52,8 @@
for (const cell of row.cells) {
let value = cell.children[0].value;
// empty => '0'
if (value === '') { value = '0' }
value = Number(value);
// NaN => 0
if (Number.isNaN(value)) value = 0;
if (value === '') { value = 0 }
else value = mathjs.parse(value).evaluate();
rowArray.push(value);
}
array.push(rowArray);
Expand Down
5 changes: 4 additions & 1 deletion matrix/operations/inverse.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ <h1 class="text-center text-color">{{ page.title }}</h1>
function to_fractions(A_inv) {
for (const i in A_inv) {
for (const j in A_inv[i]) {
A_inv[i][j] = mathjs.format(mathjs.fraction(A_inv[i][j]), { fraction: 'ratio' })
let v = A_inv[i][j];
if (v !== 0 && (v = mathjs.fraction(v)).d !== 1) {
A_inv[i][j] = mathjs.format(v, { fraction: 'ratio' })
}
}
}
return A_inv;
Expand Down

1 comment on commit c5d2256

@DataSaiyentist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main issue from line 55 to 58 was corrected: Now real numbers other than natural numbers are not replaced with 0.

Please sign in to comment.