91 lines
2.1 KiB
C++
91 lines
2.1 KiB
C++
#include "Vect.h"
|
|
|
|
#include "Gauss.h"
|
|
#include "Solver.h"
|
|
#include <cassert>
|
|
#include <iostream>
|
|
|
|
Vect::Vect(const Matrix& mat) : m_Data(mat) {
|
|
Simplify();
|
|
}
|
|
|
|
void Vect::Simplify() {
|
|
Matrix mat = m_Data;
|
|
for (std::size_t j = 0; j < mat.GetColumnCount(); j++) {
|
|
std::size_t i;
|
|
for (i = 0; i < mat.GetRawCount(); i++) {
|
|
if (!IsEqualZero(mat.at(i, j)))
|
|
break;
|
|
}
|
|
if (i == mat.GetRawCount()) {
|
|
m_Data = mat.SubMatrix(0, 0, mat.GetRawCount(), j);
|
|
return;
|
|
}
|
|
}
|
|
m_Data = mat;
|
|
}
|
|
|
|
std::size_t Vect::GetCardinal() const {
|
|
return m_Data.GetColumnCount();
|
|
}
|
|
|
|
bool Vect::operator==(const Vect& other) const {
|
|
if (GetDimension() != other.GetDimension() || GetCardinal() != other.GetCardinal())
|
|
return false;
|
|
|
|
// on vérifie si chaque vecteur de la deuxième base appartient à la première base
|
|
for (std::size_t i = 0; i < GetCardinal(); i++) {
|
|
Vect base = *this;
|
|
base.AddVector(other.m_Data.SubMatrix(0, i, GetDimension(), 1));
|
|
if (base.GetCardinal() != GetCardinal())
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void Vect::AddVector(const Matrix& mat) {
|
|
m_Data.Augmenter(mat);
|
|
m_Data.Transpose();
|
|
Gauss::GaussJordan(m_Data, false, false);
|
|
m_Data.Transpose();
|
|
Simplify();
|
|
}
|
|
|
|
bool Vect::operator!=(const Vect& other) const {
|
|
return !(*this == other);
|
|
}
|
|
|
|
Matrix Vect::GetLinearSystem() const {
|
|
Matrix vect = m_Data;
|
|
vect.Transpose();
|
|
|
|
Solver solver {vect};
|
|
vect = solver.Noyau().m_Data;
|
|
vect.Transpose();
|
|
return vect;
|
|
}
|
|
|
|
void Vect::Print() const {
|
|
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 j = 0; j < m_Data.GetColumnCount(); j++) {
|
|
std::cout << "[ " << m_Data.at(i, j) << " ]\t";
|
|
}
|
|
std::cout << "\n";
|
|
}
|
|
}
|
|
|
|
std::size_t Vect::GetDimension() const {
|
|
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();
|
|
}
|