28bf548be956fa98bffa377e2caba5f28fb281adtavmjong-free * Auxiliary routines to solve systems of linear equations in several variants and sizes.
28bf548be956fa98bffa377e2caba5f28fb281adtavmjong-free * Maximilian Albert <Anhalter42@gmx.de>
28bf548be956fa98bffa377e2caba5f28fb281adtavmjong-free * Copyright (C) 2007 Authors
28bf548be956fa98bffa377e2caba5f28fb281adtavmjong-free * Released under GNU GPL, read the file 'COPYING' for more information
28bf548be956fa98bffa377e2caba5f28fb281adtavmjong-free solution_exists // FIXME: remove this; does not yield enough information
28bf548be956fa98bffa377e2caba5f28fb281adtavmjong-free/* Determinant of the 3x3 matrix having a, b, and c as columns */
28bf548be956fa98bffa377e2caba5f28fb281adtavmjong-freedeterminant3v (const double a[3], const double b[3], const double c[3]) {
28bf548be956fa98bffa377e2caba5f28fb281adtavmjong-free/* Copy the elements of A into B */
28bf548be956fa98bffa377e2caba5f28fb281adtavmjong-freeinline void copy_mat(double A[S][T], double B[S][T]) {
28bf548be956fa98bffa377e2caba5f28fb281adtavmjong-free for (int i = 0; i < S; ++i) {
28bf548be956fa98bffa377e2caba5f28fb281adtavmjong-free for (int j = 0; j < T; ++j) {
28bf548be956fa98bffa377e2caba5f28fb281adtavmjong-free B[i][j] = A[i][j];
28bf548be956fa98bffa377e2caba5f28fb281adtavmjong-free std::cout.setf(std::ios::left, std::ios::internal);
28bf548be956fa98bffa377e2caba5f28fb281adtavmjong-free for (int i = 0; i < S; ++i) {
28bf548be956fa98bffa377e2caba5f28fb281adtavmjong-free for (int j = 0; j < T; ++j) {
template <int S, int U, int T>
sum += A[i][k] * B[k][j];
template <int S, int T>
sum += A[i][k] * v[k];
// Remark: Since we are using templates, we cannot separate declarations from definitions (which would
template <int S, int T>
pos = j;
return pos;
template <int S, int T>
if (k == row) continue;
if (l == col) continue;
if (k == row) continue;
if (l == col) continue;
* Perform Gauss-Jordan elimination on the matrix A, optionally avoiding a given column during pivot search
template <int S, int T>
/* for each row find a pivot element of maximal absolute value, skipping the columns that were used before */
return cols_used;
return cols_used;
/* compute the modified value that x[index] needs to assume so that in the end we have x[index]/x[T-1] = val */
template <int S, int T>
if (j == index) continue;
sp += B[c][j] * x[j];
return val_proj;
/* the vector x is filled with the coefficients of the desired solution vector at appropriate places;
x[cols[j]] = v[j];
x[cols[j]] = w[j];