33#include <NDEVR/Matrix.h>
36 template<
class t_type, u
int01 t_m, u
int01 t_n>
46 for (
uint01 i = 0; i < t_m; i++)
56 for (
uint01 j = 0; j < t_n; j++)
60 for (
uint01 i = 0; i < t_m; i++)
65 for (
uint01 i = 0; i < t_m; i++)
73 for (
uint01 k = 0; k < kmax; k++)
74 s += LUrowi[k] * LUcolj[k];
76 LUrowi[j] = LUcolj[i] -= s;
82 for (
uint01 i = j + 1; i < t_m; i++)
84 if (
abs(LUcolj[i]) >
abs(LUcolj[p]))
89 for (
uint01 k = 0; k < t_n; k++)
91 std::swap(LU[p][k], LU[j][k]);
93 std::swap(piv[p], piv[j]);
99 if (j < t_m && LU[j][j] != 0.0)
101 for (
uint01 i = j + 1; i < t_m; i++) {
102 LU[i][j] /= LU[j][j];
118 for (
uint01 j = 0; j < t_n; j++)
133 for (
uint01 i = 0; i < t_m; i++)
135 for (
uint01 j = 0; j < t_n; j++)
138 mat[i][j] = LU[i][j];
140 mat[i][j] = t_type(1);
142 mat[i][j] = t_type(0);
155 for (
uint01 i = 0; i < t_n; i++)
157 for (
uint01 j = 0; j < t_n; j++)
160 mat[i][j] = LU[i][j];
162 mat[i][j] = t_type(0);
171 template<
class t_pivot_type = s
int04>
174 return piv.template as<t_m, t_pivot_type>();
184 static_assert(t_m == t_n,
"Matrix must be square.");
186 for (
uint01 j = 0; j < t_n; j++)
197 template<u
int01 t_nx>
206 for (
uint01 k = 0; k < t_n; k++)
208 for (
uint01 i = k + 1; i < t_n; i++)
210 for (
uint01 j = 0; j < t_nx; j++)
212 mat[i][j] -= mat[k][j] * LU[i][k];
219 for (
uint01 j = 0; j < t_nx; j++)
220 mat[k][j] /= LU[k][k];
221 for (
uint01 i = 0; i < k; i++)
223 for (
uint01 j = 0; j < t_nx; j++)
224 mat[i][j] -= mat[k][j] * LU[i][k];
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:70
Definition LUDecomposition.hpp:38
Matrix< t_type, t_m, t_nx > solve(const Matrix< t_type, t_m, t_nx > &B)
Definition LUDecomposition.hpp:198
LUDecomposition(const Matrix< t_type, t_m, t_n > &A)
Definition LUDecomposition.hpp:40
bool isNonsingular() const
Definition LUDecomposition.hpp:116
Matrix< t_type, t_m, t_n > getU() const
Definition LUDecomposition.hpp:152
Vector< t_m, t_pivot_type > getPivot() const
Definition LUDecomposition.hpp:172
t_type det() const
Definition LUDecomposition.hpp:182
Matrix< t_type, t_m, t_n > getL() const
Definition LUDecomposition.hpp:130
Definition Matrix.hpp:173
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
int32_t sint04
-Defines an alias representing a 4 byte, signed integer. -Can represent exact integer values -2147483...
Definition BaseValues.hpp:76
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514
constexpr Angle< t_angle_type > abs(const Angle< t_angle_type > &value)
Definition AngleFunctions.h:750
constexpr bool isNaN(const t_type &value)
Query if 'value' is valid or invalid.
Definition BaseFunctions.hpp:200
@ B
Definition BaseValues.hpp:203
@ A
Definition BaseValues.hpp:201
constexpr t_type getMin(const t_type &left, const t_type &right)
Finds the minimum of the given arguments based on the < operator.
Definition BaseFunctions.hpp:67