summaryrefslogtreecommitdiff
path: root/math/gauss.cpp
diff options
context:
space:
mode:
authormzuenni <michi.zuendorf@gmail.com>2022-06-27 17:19:28 +0200
committermzuenni <michi.zuendorf@gmail.com>2022-06-27 17:19:28 +0200
commit5ab8a5088b729a9953b8dff1b2a985dc8fb2098b (patch)
treeed40d6936c0e9eee40ba62751cbf99ecddbaddc2 /math/gauss.cpp
parentadabbad9c51cf7cd3874bfde8eac1fbcf84fec10 (diff)
updated tcr
Diffstat (limited to 'math/gauss.cpp')
-rw-r--r--math/gauss.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/math/gauss.cpp b/math/gauss.cpp
index b8e43d4..0c7ab03 100644
--- a/math/gauss.cpp
+++ b/math/gauss.cpp
@@ -1,8 +1,3 @@
-// Laufzeit: O(n^3)
-void swapLines(int n, int l1, int l2) {
- for (int i = 0; i <= n; i++) swap(mat[l1][i], mat[l2][i]);
-}
-
void normalLine(int n, int line) {
double factor = mat[line][line];
for (int i = 0; i <= n; i++) {
@@ -17,7 +12,7 @@ void takeAll(int n, int line) {
mat[i][j] -= diff * mat[line][j];
}}}
-int gauss(int n) { // Gibt zurück, ob das System (eindeutig) lösbar ist.
+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.
@@ -25,12 +20,13 @@ int gauss(int n) { // Gibt zurück, ob das System (eindeutig) lösbar ist.
if (done[j]) continue;
if (abs(mat[j][i]) > abs(mat[i][i])) swappee = j;
}
- swapLines(n, i, swappee);
+ swap(mat[i], mat[swappee]);
if (abs(mat[i][i]) > EPSILON) {
normalLine(n, i);
takeAll(n, i);
done[i] = true;
- }} // Ab jetzt nur noch checks bzgl. Eindeutigkeit/Existenz der Lösung.
+ }}
+ // 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++)