|
| 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 | + |
| 4 | +where  and . |
| 5 | + |
| 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 | + |
| 46 | +and |
| 47 | + |
| 48 | +The solution is then obtained by back substitution: |
| 49 | + |
| 50 | + |
| 51 | +The method above preserves the original coefficient vectors. If this is not required, then a much simpler form of the algorithm is |
| 52 | + |
| 53 | +followed by the back substitution |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | +Reference: https://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm |
0 commit comments