summaryrefslogtreecommitdiff
path: root/content/math/gauss.cpp
diff options
context:
space:
mode:
authormzuenni <michi.zuendorf@gmail.com>2024-09-07 23:41:49 +0200
committermzuenni <michi.zuendorf@gmail.com>2024-09-07 23:41:49 +0200
commit9e9c033aa41f786f494cadea43563f83f3e951a3 (patch)
tree46413539a25f553d8b1b0d5cab7d38dcf0305759 /content/math/gauss.cpp
parentacdc3eaf1035fd840ee5b522f98bcae6d28464e2 (diff)
insert divsum
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;