LU and LU inverse is done

This commit is contained in:
2025-09-14 18:35:37 +02:00
parent 88087ea6a6
commit 92437e5ef1
23 changed files with 503 additions and 978 deletions
+4 -11
View File
@@ -23,8 +23,11 @@ namespace numerics{
if (method == "Gauss-Jordan"){
inverse_gj(A);
}
else if(method == "LU"){
inplace_inverse_lu(A);
}
else{
throw std::runtime_error("numerics::inplace_inverse(" + method + ") - Not implemented yet \r \nImplemented: 'Gauss-Jordan',");
throw std::runtime_error("numerics::inplace_inverse(" + method + ") - Not implemented yet \r \nImplemented: 'Gauss-Jordan', 'LU'");
}
}
@@ -32,21 +35,11 @@ namespace numerics{
template <typename T>
utils::Matrix<T> inverse(utils::Matrix<T>& A, std::string method = "Gauss-Jordan"){
utils::Matrix<T> B = A;
inplace_inverse(B, method);
return B;
}
} // namespace numerics
#endif // _inverse_n_
@@ -7,12 +7,13 @@
#include <omp.h>
namespace numerics{
template <typename T>
void inverse_gj(utils::Matrix<T>& A){
utils::Matrix<T> B(A.rows(),A.cols(), T{0});
//utils::Matrix<T> B(A.rows(),A.cols(), T{0});
utils::Matrix<T> B;
B.eye(A.rows());
uint64_t icol{0}, irow{0}, rows{A.rows()}, cols{A.cols()};
@@ -36,6 +37,9 @@ namespace numerics{
}
}
}
if (big <= T{1e-14}){
throw std::runtime_error("utill:inplace_inverse('Gauss-Jordan' - Singular Matrix");
}
ipiv[icol]++;
if (irow != icol){
for (uint64_t l = 0; l < rows; l++){ // SWAP
+20
View File
@@ -0,0 +1,20 @@
#pragma once
#include "./decomp/lu.h"
namespace numerics{
template <typename T>
void inplace_inverse_lu(utils::Matrix<T>& A){
if (A.rows() != A.cols()){
throw std::runtime_error("numerics inverse_lu: non-square matrix");
}
decomp::LUdcmp<T> lu(A);
lu.inplace_inverse(A);
}
}