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
Next Next commit
corrected code style
  • Loading branch information
Yordrar committed Oct 12, 2018
commit cd17d98b35d85029707404f56e35f5b975ba7bd4
18 changes: 9 additions & 9 deletions contents/thomas_algorithm/code/javascript/thomas.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
function thomas(a, b, c, x) {
let y = [];
const y = [];

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

for (let i = 1; i < a.length; i++) {
let scale = 1.0 / (b[i] - a[i] * y[i - 1]);
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;
}

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

return x;
}

let a = [0.0, 2.0, 3.0];
let b = [1.0, 3.0, 6.0];
let c = [4.0, 5.0, 0.0];
let x = [7.0, 5.0, 3.0];
let a = [0, 2, 3];
let b = [1, 3, 6];
let c = [4, 5, 0];
let x = [7, 5, 3];

console.log("The system,");
console.log("[1.0 4.0 0.0][x] = [7.0]");
console.log("[2.0 3.0 5.0][y] = [5.0]");
console.log("[0.0 3.0 6.0][z] = [3.0]");
console.log("has the solution:\n", x);

thomas(a, b, c, x);
console.log("has the solution:\n", thomas(a, b, c, x));