diff options
| author | mzuenni <michi.zuendorf@gmail.com> | 2023-02-27 15:37:24 +0100 |
|---|---|---|
| committer | mzuenni <michi.zuendorf@gmail.com> | 2023-02-27 15:49:27 +0100 |
| commit | b067d9880606143ac4b860beff4d5b02e7d349bd (patch) | |
| tree | a269c8c18c0adf05d63df08bab6d3594fee1311f /math/gauss.cpp | |
| parent | 208388a728ee7d7ea8f33952a15bb71c27740e50 (diff) | |
improved math
Diffstat (limited to 'math/gauss.cpp')
| -rw-r--r-- | math/gauss.cpp | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/math/gauss.cpp b/math/gauss.cpp index 0c7ab03..3e3b7aa 100644 --- a/math/gauss.cpp +++ b/math/gauss.cpp @@ -1,8 +1,7 @@ -void normalLine(int n, int line) { +void normalLine(int line) { double factor = mat[line][line]; - for (int i = 0; i <= n; i++) { - mat[line][i] /= factor; -}} + for (double& x : mat[line]) x /= factor; +} void takeAll(int n, int line) { for (int i = 0; i < n; i++) { @@ -21,18 +20,17 @@ int gauss(int n) { if (abs(mat[j][i]) > abs(mat[i][i])) swappee = j; } swap(mat[i], mat[swappee]); - if (abs(mat[i][i]) > EPSILON) { - normalLine(n, i); + if (abs(mat[i][i]) > EPS) { + normalLine(i); takeAll(n, i); done[i] = true; }} // Ab jetzt nur checks bzgl. Eindeutigkeit/Existenz der Lösung. for (int i = 0; i < n; i++) { bool allZero = true; - for (int j = i; j < n; j++) - if (abs(mat[i][j]) > EPSILON) allZero = false; - if (allZero && abs(mat[i][n]) > EPSILON) return INCONSISTENT; - if (allZero && abs(mat[i][n]) < EPSILON) return MULTIPLE; + for (int j = i; j < n; j++) allZero &= abs(mat[i][j]) <= EPS; + if (allZero && abs(mat[i][n]) > EPS) return INCONSISTENT; + if (allZero && abs(mat[i][n]) <= EPS) return MULTIPLE; } return UNIQUE; } |
