Compare commits
4 Commits
a016163b86
...
4ffeea8900
| Author | SHA1 | Date | |
|---|---|---|---|
| 4ffeea8900 | |||
| e1f501237d | |||
| 8ef738db55 | |||
| cf64e4d33c |
@@ -109,15 +109,18 @@ void Matrix::Transpose() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Matrix::Identity() {
|
void Matrix::Identity() {
|
||||||
|
assert(m_Lignes == m_Colonnes);
|
||||||
for (std::size_t i = 0; i < m_Lignes; i++) {
|
for (std::size_t i = 0; i < m_Lignes; i++) {
|
||||||
for (std::size_t j = i; j < m_Colonnes; j++) {
|
for (std::size_t j = i; j < m_Colonnes; j++) {
|
||||||
if (i != j) {
|
at(i, j) = i == j;
|
||||||
at(i, j) = 0;
|
|
||||||
} else {
|
|
||||||
at(i, j) = 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Matrix Matrix::Identity(std::size_t taille) {
|
||||||
|
Matrix id{taille, taille};
|
||||||
|
id.Identity();
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matrix::IsInversed() const {
|
bool Matrix::IsInversed() const {
|
||||||
@@ -133,6 +136,25 @@ bool Matrix::IsInversed() const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Matrix::Augmenter(const Matrix& droite) {
|
||||||
|
assert(droite.m_Lignes == m_Lignes);
|
||||||
|
Matrix temp{m_Lignes, m_Colonnes + droite.m_Colonnes};
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < m_Lignes; i++) {
|
||||||
|
for (std::size_t j = 0; j < m_Colonnes; j++) {
|
||||||
|
temp.at(i, j) = at(i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < m_Lignes; i++) {
|
||||||
|
for (std::size_t j = 0; j < droite.m_Colonnes; j++) {
|
||||||
|
temp.at(i, j + m_Colonnes) = droite.at(i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*this = temp;
|
||||||
|
}
|
||||||
|
|
||||||
bool Matrix::operator==(const Matrix& other) const {
|
bool Matrix::operator==(const Matrix& other) const {
|
||||||
if (m_Lignes != other.m_Lignes || m_Colonnes != other.m_Colonnes)
|
if (m_Lignes != other.m_Lignes || m_Colonnes != other.m_Colonnes)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -40,8 +40,12 @@ class Matrix {
|
|||||||
|
|
||||||
void Identity();
|
void Identity();
|
||||||
|
|
||||||
|
static Matrix Identity(std::size_t taille);
|
||||||
|
|
||||||
bool IsInversed() const;
|
bool IsInversed() const;
|
||||||
|
|
||||||
|
void Augmenter(const Matrix& droite);
|
||||||
|
|
||||||
Matrix SubMatrix(std::size_t origine_ligne, std::size_t origine_colonne, std::size_t ligne, std::size_t colonne) const;
|
Matrix SubMatrix(std::size_t origine_ligne, std::size_t origine_colonne, std::size_t ligne, std::size_t colonne) const;
|
||||||
|
|
||||||
bool operator==(const Matrix& other) const;
|
bool operator==(const Matrix& other) const;
|
||||||
|
|||||||
31
src/Solver.cpp
Normal file
31
src/Solver.cpp
Normal 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
16
src/Solver.h
Normal 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;
|
||||||
|
};
|
||||||
@@ -22,7 +22,7 @@ void Vect::Simplify() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Vect::Print() const {
|
void Vect::Print() const {
|
||||||
std::cout << "Espace vectoriel de dimension " << m_Data.GetColumnCount() << " de base :\n\n";
|
std::cout << "Espace vectoriel de dimension " << GetDimension() << " 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("[ %.3f ]\t", static_cast<float>(m_Data.at(i, j)));
|
||||||
@@ -30,3 +30,7 @@ void Vect::Print() const {
|
|||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::size_t Vect::GetDimension() const {
|
||||||
|
return m_Data.GetColumnCount();
|
||||||
|
}
|
||||||
@@ -20,6 +20,8 @@ class Vect {
|
|||||||
*/
|
*/
|
||||||
void Print() const;
|
void Print() const;
|
||||||
|
|
||||||
|
std::size_t GetDimension() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Simplify();
|
void Simplify();
|
||||||
};
|
};
|
||||||
22
src/main.cpp
22
src/main.cpp
@@ -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.Print();
|
||||||
|
|
||||||
mat2.Transpose();
|
Solver solver{mat2};
|
||||||
std::cout << "Transposée : \n";
|
|
||||||
mat2.Print();
|
|
||||||
|
|
||||||
mat2.GaussJordan(true);
|
std::cout << "\tImage :\n";
|
||||||
mat2.Transpose();
|
solver.Image().Print();
|
||||||
|
std::cout << "\tNoyau :\n";
|
||||||
std::cout << "Echelonnée en colonne :\n";
|
solver.Noyau().Print();
|
||||||
mat2.Print();
|
|
||||||
|
|
||||||
Vect sol {mat2};
|
|
||||||
sol.Print();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void prompt() {
|
void prompt() {
|
||||||
|
|||||||
Reference in New Issue
Block a user