MCPcopy Create free account
hub / github.com/algorithm-archivists/algorithm-archive / thomas

Function thomas

contents/thomas_algorithm/code/c/thomas.c:4–22  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include <string.h>
3
4void thomas(double * const a, double * const b, double * const c,
5 double * const x, const size_t size) {
6
7 double y[size];
8 memset(y, 0, size * sizeof(double));
9
10 y[0] = c[0] / b[0];
11 x[0] = x[0] / b[0];
12
13 for (size_t i = 1; i < size; ++i) {
14 double scale = 1.0 / (b[i] - a[i] * y[i - 1]);
15 y[i] = c[i] * scale;
16 x[i] = (x[i] - a[i] * x[i - 1]) * scale;
17 }
18
19 for (size_t i = size - 2; i < size - 1; --i) {
20 x[i] -= y[i] * x[i + 1];
21 }
22}
23
24int main() {
25 double a[] = {0.0, 2.0, 3.0};

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected