6 #include "densematrix.hh" 19 HDNUM_ERROR(
"need square and nonempty matrix");
21 HDNUM_ERROR(
"permutation vector incompatible with matrix");
24 for (std::size_t k=0; k<A.
rowsize()-1; ++k)
27 for (std::size_t r=k; r<A.
rowsize(); ++r)
32 for (std::size_t j=0; j<A.
colsize(); ++j)
40 if (A[k][k]==0) HDNUM_ERROR(
"matrix is singular");
43 for (std::size_t i=k+1; i<A.
rowsize(); ++i)
45 T qik(A[i][k]/A[k][k]);
47 for (std::size_t j=k+1; j<A.
colsize(); ++j)
48 A[i][j] -= qik * A[k][j];
68 HDNUM_ERROR(
"need square and nonempty matrix");
70 HDNUM_ERROR(
"permutation vector incompatible with matrix");
73 for (std::size_t k=0; k<A.
rowsize(); ++k)
77 for (std::size_t k=0; k<A.
rowsize()-1; ++k)
80 for (std::size_t r=k+1; r<A.
rowsize(); ++r)
81 if (
abs(A[r][k])>
abs(A[k][k]))
85 for (std::size_t j=0; j<A.
colsize(); ++j)
92 if (A[k][k]==0) HDNUM_ERROR(
"matrix is singular");
95 for (std::size_t i=k+1; i<A.
rowsize(); ++i)
97 T qik(A[i][k]/A[k][k]);
99 for (std::size_t j=k+1; j<A.
colsize(); ++j)
100 A[i][j] -= qik * A[k][j];
110 HDNUM_ERROR(
"need square and nonempty matrix");
112 HDNUM_ERROR(
"permutation vector incompatible with matrix");
115 for (std::size_t k=0; k<A.
rowsize(); ++k)
119 for (std::size_t k=0; k<A.
rowsize()-1; ++k)
122 for (std::size_t r=k; r<A.
rowsize(); ++r)
123 for (std::size_t s=k; s<A.
colsize(); ++s)
124 if (
abs(A[r][s])>
abs(A[k][k]))
131 for (std::size_t j=0; j<A.
colsize(); ++j)
134 A[k][j] = A[p[k]][j];
138 for (std::size_t i=0; i<A.
rowsize(); ++i)
141 A[i][k] = A[i][q[k]];
145 if (A[k][k]==0) HDNUM_ERROR(
"matrix is singular");
148 for (std::size_t i=k+1; i<A.
rowsize(); ++i)
150 T qik(A[i][k]/A[k][k]);
152 for (std::size_t j=k+1; j<A.
colsize(); ++j)
153 A[i][j] -= qik * A[k][j];
162 if (b.size()!=p.size())
163 HDNUM_ERROR(
"permutation vector incompatible with rhs");
165 for (std::size_t k=0; k<b.size()-1; ++k)
178 if (z.size()!=q.size())
179 HDNUM_ERROR(
"permutation vector incompatible with z");
181 for (
int k=z.size()-2; k>=0; --k)
182 if (q[k]!=std::size_t(k))
195 HDNUM_ERROR(
"need nonempty matrix");
197 HDNUM_ERROR(
"scaling vector incompatible with matrix");
200 for (std::size_t k=0; k<A.
rowsize(); ++k)
203 for (std::size_t j=0; j<A.
colsize(); ++j)
204 s[k] +=
abs(A[k][j]);
205 if (s[k]==0) HDNUM_ERROR(
"row sum is zero");
206 for (std::size_t j=0; j<A.
colsize(); ++j)
215 if (s.size()!=b.size())
216 HDNUM_ERROR(
"s and b incompatible");
219 for (std::size_t k=0; k<b.size(); ++k)
228 HDNUM_ERROR(
"need square and nonempty matrix");
230 HDNUM_ERROR(
"right hand side incompatible with matrix");
232 for (std::size_t i=0; i<A.
rowsize(); ++i)
235 for (std::size_t j=0; j<i; j++)
236 rhs -= A[i][j] * x[j];
246 HDNUM_ERROR(
"need square and nonempty matrix");
248 HDNUM_ERROR(
"right hand side incompatible with matrix");
250 for (
int i=A.
rowsize()-1; i>=0; --i)
253 for (std::size_t j=i+1; j<A.
colsize(); j++)
254 rhs -= A[i][j] * x[j];
Class with mathematical vector operations.
Definition: vector.hh:28
void lr_fullpivot(DenseMatrix< T > &A, Vector< std::size_t > &p, Vector< std::size_t > &q)
lr decomposition of A with full pivoting
Definition: lr.hh:107
void permute_backward(const Vector< std::size_t > &q, Vector< T > &z)
apply permutations to a solution vector
Definition: lr.hh:176
void solveR(const DenseMatrix< T > &A, Vector< T > &x, const Vector< T > &b)
Assume R = upper triangle of A and solve R x = b.
Definition: lr.hh:243
void row_equilibrate(DenseMatrix< T > &A, Vector< T > &s)
perform a row equilibration of a matrix; return scaling for later use
Definition: lr.hh:192
void apply_equilibrate(Vector< T > &s, Vector< T > &b)
apply row equilibration to right hand side vector
Definition: lr.hh:213
void solveL(const DenseMatrix< T > &A, Vector< T > &x, const Vector< T > &b)
Assume L = lower triangle of A with l_ii=1, solve L x = b.
Definition: lr.hh:225
size_t rowsize() const
get number of rows of the matrix
Definition: densematrix.hh:121
size_t colsize() const
get number of columns of the matrix
Definition: densematrix.hh:141
Class with mathematical matrix operations.
Definition: densematrix.hh:26
void lr_partialpivot(DenseMatrix< T > &A, Vector< std::size_t > &p)
lr decomposition of A with column pivoting
Definition: lr.hh:65
void permute_forward(const Vector< std::size_t > &p, Vector< T > &b)
apply permutations to a right hand side vector
Definition: lr.hh:160
T abs(const T &t)
our own abs class that works also for multiprecision types
Definition: lr.hh:55
Definition: densematrix.hh:21
void lr(DenseMatrix< T > &A, Vector< std::size_t > &p)
compute lr decomposition of A with first nonzero pivoting
Definition: lr.hh:16