Skip to content

Commit 05e9e39

Browse files
committed
v1.0.0
1 parent 086e54b commit 05e9e39

File tree

16 files changed

+1044
-0
lines changed

16 files changed

+1044
-0
lines changed

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# TDMA (Tridiagonal matrix algorithm)
2+
In numerical linear algebra, the tridiagonal matrix algorithm, also known as the Thomas algorithm (named after Llewellyn Thomas), is a simplified form of Gaussian elimination that can be used to solve tridiagonal systems of equations. A tridiagonal system for n unknowns may be written as
3+
![Equations](docs/1.svg)
4+
where ![Equations](docs/2.svg) and ![Equations](docs/3.svg).
5+
![Equations](docs/4.svg)
6+
7+
## Install
8+
```
9+
npm install tdma
10+
```
11+
12+
## Sample Code
13+
Using coefficientMatrix
14+
```
15+
const tdma = require('tdma');
16+
17+
const coefficientMatrix = [
18+
[2, 3, 0, 0],
19+
[6, 3, 9, 0],
20+
[0, 2, 5, 2],
21+
[0, 0, 4, 3]
22+
];
23+
const rigthHandSideVector = [21, 69, 34, 22];
24+
25+
const answer = tdma.solver(coefficientMatrix, rigthHandSideVector);
26+
console.log(answer);
27+
```
28+
29+
Using Diagonals
30+
```
31+
const tdma = require('tdma');
32+
33+
const a = [0, 6, 2, 4];
34+
const b = [2, 3, 5, 3];
35+
const c = [3, 9, 2, 0];
36+
const d = [21, 69, 34, 22];
37+
38+
const answer = tdma.tdma(a, b, c, d);
39+
console.log(answer);
40+
```
41+
42+
43+
## Method
44+
The forward sweep consists of modifying the coefficients as follows, denoting the new coefficients with primes:
45+
![Equations](docs/5.svg)
46+
and
47+
![Equations](docs/6.svg)
48+
The solution is then obtained by back substitution:
49+
![Equations](docs/7.svg)
50+
![Equations](docs/8.svg)
51+
The method above preserves the original coefficient vectors. If this is not required, then a much simpler form of the algorithm is
52+
![Equations](docs/9.svg)
53+
followed by the back substitution
54+
![Equations](docs/10.svg)
55+
![Equations](docs/11.svg)
56+
57+
Reference: https://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm

docs/1.svg

Lines changed: 56 additions & 0 deletions
Loading

docs/10.svg

Lines changed: 91 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)