summaryrefslogtreecommitdiff
path: root/content/math/gauss.cpp
diff options
context:
space:
mode:
authorGloria Mundi <gloria@gloria-mundi.eu>2024-11-16 15:39:23 +0100
committerGloria Mundi <gloria@gloria-mundi.eu>2024-11-16 15:39:23 +0100
commit72bd993483453ed8ebc462f1a33385cd355d486f (patch)
treec5592ba1ed2fed79e26ba6158d097c9ceb43f061 /content/math/gauss.cpp
parent98567ec798aa8ca2cfbcb85c774dd470f30e30d4 (diff)
parent35d485bcf6a9ed0a9542628ce4aa94a3326d0884 (diff)
merge mzuenni changes
Diffstat (limited to 'content/math/gauss.cpp')
-rw-r--r--content/math/gauss.cpp12
1 files changed, 5 insertions, 7 deletions
diff --git a/content/math/gauss.cpp b/content/math/gauss.cpp
index 8129fd2..d431e52 100644
--- a/content/math/gauss.cpp
+++ b/content/math/gauss.cpp
@@ -14,19 +14,17 @@ void takeAll(int n, int line) {
int gauss(int n) {
vector<bool> done(n, false);
for (int i = 0; i < n; i++) {
- int swappee = i; // Sucht Pivotzeile für bessere Stabilität.
- for (int j = 0; j < n; j++) {
- if (done[j]) continue;
- if (abs(mat[j][i]) > abs(mat[i][i])) swappee = j;
+ int j = i; // Sucht Pivotzeile für bessere Stabilität.
+ for (int k = 0; k < n; k++) {
+ if (!done[k] && abs(mat[k][i]) > abs(mat[i][i])) j = k;
}
- swap(mat[i], mat[swappee]);
+ swap(mat[i], mat[j]);
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++) {
+ for (int i = 0; i < n; i++) { // gauss fertig, prüfe Lösung
bool allZero = true;
for (int j = i; j < n; j++) allZero &= abs(mat[i][j]) <= EPS;
if (allZero && abs(mat[i][n]) > EPS) return INCONSISTENT;