image et noyau
All checks were successful
Linux arm64 / Build (push) Successful in 36s

This commit is contained in:
2024-02-14 21:35:26 +01:00
parent e1f501237d
commit 4ffeea8900
3 changed files with 57 additions and 16 deletions

31
src/Solver.cpp Normal file
View File

@@ -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();
}

16
src/Solver.h Normal file
View File

@@ -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;
};

View File

@@ -1,8 +1,8 @@
#include "Vect.h" #include "Solver.h"
#include <iostream> #include <iostream>
void test() { void test() {
Matrix mat{"matrice4x4.mat"}; /* Matrix mat{"matrice4x4.mat"};
mat.Print(); mat.Print();
// mat.Save("matrice3x3.mat"); // mat.Save("matrice3x3.mat");
std::cout << "sdfdjiofoseifheoiefhoig\n"; std::cout << "sdfdjiofoseifheoiefhoig\n";
@@ -14,23 +14,17 @@ void test() {
mat.Transpose(); mat.Transpose();
std::cout << "<<\nTransposée:\n"; std::cout << "<<\nTransposée:\n";
mat.Print(); mat.Print();
// mat.Save("matrice4x4echelonne.mat"); // mat.Save("matrice4x4echelonne.mat"); */
Matrix mat2 {"matrice4x4.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";
mat2.Print(); mat2.Print();
Vect sol {mat2}; Solver solver{mat2};
sol.Print();
std::cout << "\tImage :\n";
solver.Image().Print();
std::cout << "\tNoyau :\n";
solver.Noyau().Print();
} }
void prompt() { void prompt() {