From 4ffeea890028784a1d7685577afe9d855d801703 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Wed, 14 Feb 2024 21:35:26 +0100 Subject: [PATCH] image et noyau --- src/Solver.cpp | 31 +++++++++++++++++++++++++++++++ src/Solver.h | 16 ++++++++++++++++ src/main.cpp | 26 ++++++++++---------------- 3 files changed, 57 insertions(+), 16 deletions(-) create mode 100644 src/Solver.cpp create mode 100644 src/Solver.h diff --git a/src/Solver.cpp b/src/Solver.cpp new file mode 100644 index 0000000..5e1634d --- /dev/null +++ b/src/Solver.cpp @@ -0,0 +1,31 @@ +#include "Solver.h" + +Solver::Solver(const Matrix& mat) : m_Matrix(mat) {} + +Vect Solver::Image() const { + Matrix result = m_Matrix; + result.Transpose(); + result.GaussJordan(true); + result.Transpose(); + return {result}; +} + +// https://en.wikipedia.org/wiki/Kernel_(linear_algebra)#Computation_by_Gaussian_elimination +Vect Solver::Noyau() const { + Matrix result = m_Matrix; + result.Transpose(); + result.Augmenter(Matrix::Identity(result.GetRawCount())); + result.GaussJordan(true); + result.Transpose(); + + // nombre de colonnes non nulles + std::size_t origine_colonne = Vect(result.SubMatrix(0, 0, m_Matrix.GetRawCount(), m_Matrix.GetColumnCount())).GetDimension(); + + return {result.SubMatrix(m_Matrix.GetRawCount(), origine_colonne, result.GetRawCount() - m_Matrix.GetRawCount(), + result.GetColumnCount() - origine_colonne)}; +} + +std::size_t Solver::Rang() const { + Vect image = Image(); + return image.GetDimension(); +} diff --git a/src/Solver.h b/src/Solver.h new file mode 100644 index 0000000..aded7b5 --- /dev/null +++ b/src/Solver.h @@ -0,0 +1,16 @@ +#pragma once + +#include "Vect.h" + +class Solver { + private: + Matrix m_Matrix; + public: + Solver(const Matrix& mat); + ~Solver() {} + + Vect Image() const; + Vect Noyau() const; + + std::size_t Rang() const; +}; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 8d66b28..30091d6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,8 @@ -#include "Vect.h" +#include "Solver.h" #include void test() { - Matrix mat{"matrice4x4.mat"}; + /* Matrix mat{"matrice4x4.mat"}; mat.Print(); // mat.Save("matrice3x3.mat"); std::cout << "sdfdjiofoseifheoiefhoig\n"; @@ -14,23 +14,17 @@ void test() { mat.Transpose(); std::cout << "<<\nTransposée:\n"; mat.Print(); - // mat.Save("matrice4x4echelonne.mat"); + // mat.Save("matrice4x4echelonne.mat"); */ - Matrix mat2 {"matrice4x4.mat"}; - mat2.Print(); - - mat2.Transpose(); - std::cout << "Transposée : \n"; - mat2.Print(); - - mat2.GaussJordan(true); - mat2.Transpose(); - - std::cout << "Echelonnée en colonne :\n"; + Matrix mat2{"matrice4x4.mat"}; mat2.Print(); - Vect sol {mat2}; - sol.Print(); + Solver solver{mat2}; + + std::cout << "\tImage :\n"; + solver.Image().Print(); + std::cout << "\tNoyau :\n"; + solver.Noyau().Print(); } void prompt() {