19using matrix = std::vector<std::valarray<T>>;
35 std::cerr <<
"Not a square matrix!\n";
40 for (row = 0; row <
mat_size; row++) {
45 for (col = row; col <
mat_size; col++) {
48 for (j = 0; j < row; j++) {
49 lu_sum += L[0][row][j] * U[0][j][col];
53 U[0][row][col] = A[row][col] - lu_sum;
60 for (col = row; col <
mat_size; col++) {
68 for (j = 0; j < row; j++) {
69 lu_sum += L[0][col][j] * U[0][j][row];
73 L[0][col][row] = (A[col][row] - lu_sum) / U[0][row][row];
98 for (
size_t i = 0; i < A.size(); i++) {
99 result *= L[i][i] * U[i][i];
double determinant_lu(const matrix< T > &A)
int lu_decomposition(const matrix< T > &A, matrix< double > *L, matrix< double > *U)
std::vector< std::valarray< T > > matrix