Skip to content

Commit 5bf615a

Browse files
leiosYordrar
andauthored
merging with master and fixing let statements (#683)
Co-authored-by: Juan Antonio Hernández Cánovas <juanantoniohernandezcanovas@gmail.com> Co-authored-by: Juan Antonio Hernández Cánovas <juanantoniohernandezcanovas@gmail.com>
1 parent 96a691a commit 5bf615a

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function thomas(a, b, c, x) {
2+
const y = [];
3+
4+
y[0] = c[0] / b[0];
5+
x[0] = x[0] / b[0];
6+
7+
for (let i = 1; i < a.length; i++) {
8+
const scale = 1.0 / (b[i] - a[i] * y[i - 1]);
9+
y[i] = c[i] * scale;
10+
x[i] = (x[i] - a[i] * x[i - 1]) * scale;
11+
}
12+
13+
for (let i = a.length - 2; i >= 0; i--)
14+
x[i] -= y[i] * x[i + 1];
15+
}
16+
17+
let a = [0.0, 2.0, 3.0];
18+
let b = [1.0, 3.0, 6.0];
19+
let c = [4.0, 5.0, 0.0];
20+
let x = [7.0, 5.0, 3.0];
21+
22+
console.log("The system,");
23+
console.log("[1.0 4.0 0.0][x] = [7.0]");
24+
console.log("[2.0 3.0 5.0][y] = [5.0]");
25+
console.log("[0.0 3.0 6.0][z] = [3.0]");
26+
console.log("has the solution:\n");
27+
28+
thomas(a, b, c, x);
29+
30+
for (let i = 0; i < 3; i++)
31+
console.log("[" + x[i] + "]");

contents/thomas_algorithm/thomas_algorithm.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ You will find this algorithm implemented [in this project](https://scratch.mit.e
131131
[import, lang:"kotlin"](code/kotlin/thomas.kt)
132132
{% sample lang="ruby" %}
133133
[import, lang="ruby"](code/ruby/thomas.rb)
134+
{% sample lang="js" %}
135+
[import, lang:"javascript"](code/javascript/thomas.js)
134136
{% endmethod %}
135137

136138
<script>

0 commit comments

Comments
 (0)