50 for (
size_t k = 0; k <
LU.
cols(); ++k) {
63 double max_elem = std::abs(
LU(k, k));
65 for (
size_t i = k + 1; i <
LU.
rows(); ++i) {
66 double abs_elem = std::abs(
LU(i, k));
67 if (abs_elem > max_elem) {
124 double pivot =
LU(k, k);
127 for (
size_t i = k + 1; i <
LU.
rows(); ++i)
131 for (
size_t c = k + 1; c <
LU.
cols(); ++c)
133 for (
size_t i = k + 1; i <
LU.
rows(); ++i)
135 LU(i, c) -=
LU(i, k) *
LU(k, c);
169 for (
size_t i = 0; i < B.
cols(); ++i) {
170 for (
size_t r =
LU.
rows(); r-- > 0;) {
172 for (
size_t c = r + 1; c <
LU.
cols(); ++c)
173 X(r, i) -=
LU(r, c) * X(c, i);
203 for (
size_t i = 0; i < B.
cols(); ++i) {
204 for (
size_t r = 0; r <
LU.
rows(); ++r) {
206 for (
size_t c = 0; c < r; ++c)
207 X(r, i) -=
LU(r, c) * X(c, i);
void swap_rows(size_t a, size_t b)
Swap two rows of the matrix.
size_t rows() const
Get the number of rows of the matrix.
size_t cols() const
Get the number of columns of the matrix.
size_t size() const
Get the size of the permutation matrix.
void permute_rows(Matrix &A) const
Apply the permutation to the rows of matrix A.
SquareMatrix LU
Result of a LU factorization: stores the upper-triangular matrix U and the strict lower-triangular pa...
void back_subs(const Matrix &B, Matrix &X) const
Back substitution algorithm for solving upper-triangular systems UX = B.
void solve_inplace(Matrix &B) const
Solve the system AX = B or LUX = B.
bool is_factored() const
Check if this object contains a factorization.
void forward_subs(const Matrix &B, Matrix &X) const
Forward substitution algorithm for solving lower-triangular systems LX = B.
void compute_factorization()
The actual LU factorization algorithm.
PermutationMatrix P
The permutation of A that maximizes pivot size.
enum RowPivotLU::State state