33#include <NDEVR/Matrix.h>
39 template<
class t_type, u
int01 t_m, u
int01 t_n>
49 for (
uint01 i = 0; i < t_m; i++)
59 for (
uint01 j = 0; j < t_n; j++)
63 for (
uint01 i = 0; i < t_m; i++)
68 for (
uint01 i = 0; i < t_m; i++)
76 for (
uint01 k = 0; k < kmax; k++)
77 s += LUrowi[k] * LUcolj[k];
79 LUrowi[j] = LUcolj[i] -= s;
85 for (
uint01 i = j + 1; i < t_m; i++)
87 if (
abs(LUcolj[i]) >
abs(LUcolj[p]))
92 for (
uint01 k = 0; k < t_n; k++)
94 std::swap(LU[p][k], LU[j][k]);
96 std::swap(piv[p], piv[j]);
102 if (j < t_m && LU[j][j] != 0.0)
104 for (
uint01 i = j + 1; i < t_m; i++) {
105 LU[i][j] /= LU[j][j];
121 for (
uint01 j = 0; j < t_n; j++)
136 for (
uint01 i = 0; i < t_m; i++)
138 for (
uint01 j = 0; j < t_n; j++)
141 mat[i][j] = LU[i][j];
143 mat[i][j] = t_type(1);
145 mat[i][j] = t_type(0);
158 for (
uint01 i = 0; i < t_n; i++)
160 for (
uint01 j = 0; j < t_n; j++)
163 mat[i][j] = LU[i][j];
165 mat[i][j] = t_type(0);
174 template<
class t_pivot_type = s
int04>
177 return piv.template as<t_m, t_pivot_type>();
187 static_assert(t_m == t_n,
"Matrix must be square.");
189 for (
uint01 j = 0; j < t_n; j++)
200 template<u
int01 t_nx>
209 for (
uint01 k = 0; k < t_n; k++)
211 for (
uint01 i = k + 1; i < t_n; i++)
213 for (
uint01 j = 0; j < t_nx; j++)
215 mat[i][j] -= mat[k][j] * LU[i][k];
222 for (
uint01 j = 0; j < t_nx; j++)
223 mat[k][j] /= LU[k][k];
224 for (
uint01 i = 0; i < k; i++)
226 for (
uint01 j = 0; j < t_nx; j++)
227 mat[i][j] -= mat[k][j] * LU[i][k];
#define lib_assert(expression, message)
Definition LibAssert.h:61
Logic for performing LU Decomposition https://en.wikipedia.org/wiki/LU_decomposition.
Definition LUDecomposition.hpp:41
Matrix< t_type, t_m, t_nx > solve(const Matrix< t_type, t_m, t_nx > &B)
Definition LUDecomposition.hpp:201
LUDecomposition(const Matrix< t_type, t_m, t_n > &A)
Definition LUDecomposition.hpp:43
bool isNonsingular() const
Definition LUDecomposition.hpp:119
Matrix< t_type, t_m, t_n > getU() const
Definition LUDecomposition.hpp:155
Vector< t_m, t_pivot_type > getPivot() const
Definition LUDecomposition.hpp:175
t_type det() const
Definition LUDecomposition.hpp:185
Matrix< t_type, t_m, t_n > getL() const
Definition LUDecomposition.hpp:133
Definition Matrix.hpp:176
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
int32_t sint04
-Defines an alias representing a 4 byte, signed integer. -Can represent exact integer values -2147483...
Definition BaseValues.hpp:64
constexpr bool IsInvalid(const t_type &value)
Query if 'value' is valid or invalid. Invalid values should return invalid if used for calculations o...
Definition BaseFunctions.hpp:170
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:375
constexpr Angle< t_angle_type > abs(const Angle< t_angle_type > &value)
Changes an input with a negative sign, to a positive sign.
Definition AngleFunctions.h:645
@ B
Definition BaseValues.hpp:170
@ A
Definition BaseValues.hpp:168
constexpr t_type getMin(const t_type &left, const t_type &right)
Finds the minimum of the given arguments based on the < operator Author: Tyler Parke Date: 2017-11-05...
Definition BaseFunctions.hpp:56