4#include "../../math/constmath.hpp"
5#include "../matrix.hpp"
6#include "../operations.hpp"
26template <
typename T, Size S>
struct LUMatrix
53template <
typename T, Size S>
59 for (Size row = 0; row <
S; ++row)
82 for (Size col = 0; col <
S; ++col)
89 for (Size col = 0; col <
diag; ++col)
101 for (Size row =
diag + 1; row <
S; ++row)
109 for (Size col =
diag; col <
S; ++col)
111 res._u(row, col) =
res._u(row, col) -
137template <
typename T, Size S>
143 for (Size row = 0; row <
S; ++row)
145 pb(row, 0) =
b(
lu._p[row], 0);
149 for (Size row = 0; row <
S; ++row)
151 T sum =
static_cast<T>(0);
152 for (Size col = 0; col < row; ++col)
156 y(row, 0) =
pb(row, 0) -
sum;
161 for (Size
i =
S;
i > 0; --
i)
164 T sum =
static_cast<T>(0);
165 for (Size col = row + 1; col <
S; ++col)
173 x(row, 0) = (
y(row, 0) -
sum) /
lu._u(row, row);
179 x(row, 0) = (
y(row, 0) -
sum) /
static_cast<T>(1
e-30);
Fixed-size matrix with compile-time dimensions.
Definition matrix.hpp:56
constexpr Matrix< T, S, 1 > lu_solve(const LUMatrix< T, S > &lu, const Matrix< T, S, 1 > &b)
Solve the linear system Ax = b given the LU factorization of A.
Definition lu.hpp:138
constexpr LUMatrix< T, S > lu(const Matrix< T, S, S > &a)
LU decomposition with partial pivoting.
Definition lu.hpp:54
constexpr T abs(const T x)
Absolute value of a real number.
Definition abs.hpp:17
constexpr T epsilon()
Machine epsilon for type T.
Definition utilities.hpp:82