From 54798d0ff2889fdecafaa0c72b4b0023fe772e17 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Wed, 21 Feb 2024 22:01:31 +0100 Subject: [PATCH] resolve rectangular systems --- src/Solver.cpp | 12 ++++++++++++ src/Solver.h | 3 +++ src/Vect.cpp | 13 ++++++++++++- src/Vect.h | 20 ++++++++++++++++++++ src/main.cpp | 3 +++ 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/Solver.cpp b/src/Solver.cpp index 336711d..ca71ef7 100644 --- a/src/Solver.cpp +++ b/src/Solver.cpp @@ -25,6 +25,18 @@ Vect Solver::Noyau() const { result.GetColumnCount() - origine_colonne)}; } +VectAffine Solver::SystemeTriangulaire() const { + Matrix mat = m_Matrix; + mat.GaussJordan(true); + + Solver solver{mat.SubMatrix(0, 0, mat.GetRawCount(), mat.GetColumnCount() - 1)}; + + Vect noyau = solver.Noyau(); + Matrix origin = mat.SubMatrix(0, mat.GetColumnCount() - 1, mat.GetRawCount(), 1); + + return {noyau, origin}; +} + std::size_t Solver::Rang() const { Vect image = Image(); return image.GetCardinal(); diff --git a/src/Solver.h b/src/Solver.h index aded7b5..f299f2e 100644 --- a/src/Solver.h +++ b/src/Solver.h @@ -5,6 +5,7 @@ class Solver { private: Matrix m_Matrix; + public: Solver(const Matrix& mat); ~Solver() {} @@ -12,5 +13,7 @@ class Solver { Vect Image() const; Vect Noyau() const; + VectAffine SystemeTriangulaire() const; + std::size_t Rang() const; }; \ No newline at end of file diff --git a/src/Vect.cpp b/src/Vect.cpp index 17c06d9..5ec21af 100644 --- a/src/Vect.cpp +++ b/src/Vect.cpp @@ -1,6 +1,7 @@ #include "Vect.h" #include "Solver.h" +#include #include Vect::Vect(const Matrix& mat) : m_Data(mat) { @@ -75,4 +76,14 @@ void Vect::Print() const { std::size_t Vect::GetDimension() const { return m_Data.GetRawCount(); -} \ No newline at end of file +} + +VectAffine::VectAffine(const Vect& base, const Matrix& origine) : + m_Base(base), m_Origin(origine.SubMatrix(0, 0, m_Base.GetDimension(), 1)) {} + +void VectAffine::Print() const { + std::cout << "\tEspace Affine :\n\n"; + m_Base.Print(); + std::cout << "\nOrigine :\n\n"; + m_Origin.Print(); +} diff --git a/src/Vect.h b/src/Vect.h index 6d5c759..9dbee22 100644 --- a/src/Vect.h +++ b/src/Vect.h @@ -36,4 +36,24 @@ class Vect { private: void Simplify(); +}; + + +class VectAffine { + private: + Vect m_Base; + Matrix m_Origin; + + public: + VectAffine(const Vect& base, const Matrix& origin); + + void Print() const; + + const Vect& GetBase() const { + return m_Base; + } + + const Matrix& GetOrigin() const { + return m_Origin; + } }; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 39d5061..d4a1693 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,6 +32,9 @@ void test() { noyau.Print(); std::cout << "Système :\n"; noyau.GetLinearSystem().Print(); + + std::cout << "\n\n"; + solver.SystemeTriangulaire().Print(); } void prompt() {