Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
corrected return value
  • Loading branch information
Yordrar committed Oct 14, 2018
commit eb04d8c7357320f73d5e83ecbbd6739d44085d23
9 changes: 5 additions & 4 deletions contents/thomas_algorithm/code/javascript/thomas.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
function thomas(a, b, c, x) {
const result = [];
const y = [];

y[0] = c[0] / b[0];
x[0] = x[0] / b[0];
result[0] = x[0] / b[0];

for (let i = 1; i < a.length; i++) {
const scale = 1 / (b[i] - a[i] * y[i - 1]);
y[i] = c[i] * scale;
x[i] = (x[i] - a[i] * x[i - 1]) * scale;
result[i] = (x[i] - a[i] * result[i - 1]) * scale;
}

for (let i = a.length - 2; i >= 0; i--)
x[i] -= y[i] * x[i + 1];
result[i] -= y[i] * result[i + 1];

return x;
return result;
}

let a = [0, 2, 3];
Expand Down