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];
Matrix< t_type, t_m, t_n > getL() const
Return lower triangular factor.
t_type det() const
Determinant.
Vector< t_m, t_pivot_type > getPivot() const
Return pivot permutation vector.
Matrix< t_type, t_m, t_nx > solve(const Matrix< t_type, t_m, t_nx > &B)
Solve A*X = B.
bool isNonsingular() const
Is the matrix nonsingular?
Matrix< t_type, t_m, t_n > getU() const
Return upper triangular factor.
Templated logic for doing matrix multiplication.
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
The primary namespace for the NDEVR SDK.
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...
static constexpr bool IsValid(const Angle< t_type > &value)
Checks whether the given Angle holds a valid value.
constexpr Angle< t_angle_type > abs(const Angle< t_angle_type > &value)
Changes an input with a negative sign, to a positive sign.
int32_t sint04
-Defines an alias representing a 4 byte, signed integer.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.