Compare commits

..

3 Commits

Author SHA1 Message Date
efd0a88868 format test_solver
All checks were successful
Linux arm64 / Build (push) Successful in 5m19s
2024-02-21 22:06:08 +01:00
54798d0ff2 resolve rectangular systems 2024-02-21 22:01:31 +01:00
99467048e2 change Vect display 2024-02-21 21:59:46 +01:00
6 changed files with 57 additions and 3 deletions

View File

@@ -25,6 +25,18 @@ Vect Solver::Noyau() const {
result.GetColumnCount() - origine_colonne)}; 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 { std::size_t Solver::Rang() const {
Vect image = Image(); Vect image = Image();
return image.GetCardinal(); return image.GetCardinal();

View File

@@ -5,6 +5,7 @@
class Solver { class Solver {
private: private:
Matrix m_Matrix; Matrix m_Matrix;
public: public:
Solver(const Matrix& mat); Solver(const Matrix& mat);
~Solver() {} ~Solver() {}
@@ -12,5 +13,7 @@ class Solver {
Vect Image() const; Vect Image() const;
Vect Noyau() const; Vect Noyau() const;
VectAffine SystemeTriangulaire() const;
std::size_t Rang() const; std::size_t Rang() const;
}; };

View File

@@ -1,6 +1,7 @@
#include "Vect.h" #include "Vect.h"
#include "Solver.h" #include "Solver.h"
#include <cassert>
#include <iostream> #include <iostream>
Vect::Vect(const Matrix& mat) : m_Data(mat) { Vect::Vect(const Matrix& mat) : m_Data(mat) {
@@ -67,7 +68,7 @@ void Vect::Print() const {
std::cout << "Espace vectoriel de dimension " << GetCardinal() << " de base :\n\n"; std::cout << "Espace vectoriel de dimension " << GetCardinal() << " de base :\n\n";
for (std::size_t i = 0; i < m_Data.GetRawCount(); i++) { for (std::size_t i = 0; i < m_Data.GetRawCount(); i++) {
for (std::size_t j = 0; j < m_Data.GetColumnCount(); j++) { for (std::size_t j = 0; j < m_Data.GetColumnCount(); j++) {
printf("[ %.3f ]\t", static_cast<float>(m_Data.at(i, j))); printf("[ %u ]\t", static_cast<float>(m_Data.at(i, j)));
} }
std::cout << "\n"; std::cout << "\n";
} }
@@ -76,3 +77,13 @@ void Vect::Print() const {
std::size_t Vect::GetDimension() const { std::size_t Vect::GetDimension() const {
return m_Data.GetRawCount(); return m_Data.GetRawCount();
} }
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();
}

View File

@@ -37,3 +37,23 @@ class Vect {
private: private:
void Simplify(); 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;
}
};

View File

@@ -32,6 +32,9 @@ void test() {
noyau.Print(); noyau.Print();
std::cout << "Système :\n"; std::cout << "Système :\n";
noyau.GetLinearSystem().Print(); noyau.GetLinearSystem().Print();
std::cout << "\n\n";
solver.SystemeTriangulaire().Print();
} }
void prompt() { void prompt() {

View File

@@ -1,17 +1,21 @@
#include "Solver.h"
#include <cassert> #include <cassert>
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include "Solver.h"
namespace fs = std::filesystem; namespace fs = std::filesystem;
int main() { int main() {
std::string path = "test"; std::string path = "test";
for (const auto& entry : fs::directory_iterator(path)) { for (const auto& entry : fs::directory_iterator(path)) {
std::string fileName = entry.path().string(); std::string fileName = entry.path().string();
std::cout << "Opening " << fileName << " ...\n"; std::cout << "Opening " << fileName << " ...\n";
std::ifstream in{fileName}; std::ifstream in{fileName};
Matrix mat{1, 1}, imageMat{1, 1}, noyauMat{1, 1}; Matrix mat{1, 1}, imageMat{1, 1}, noyauMat{1, 1};
in >> mat >> imageMat >> noyauMat; in >> mat >> imageMat >> noyauMat;
@@ -19,6 +23,7 @@ int main() {
Vect noyau{noyauMat}; Vect noyau{noyauMat};
Solver solver{mat}; Solver solver{mat};
assert(solver.Image() == image); assert(solver.Image() == image);
assert(solver.Noyau() == noyau); assert(solver.Noyau() == noyau);
} }