add IsElementOf + ColumnVector

This commit is contained in:
2024-03-03 12:16:26 +01:00
parent 9d3d78fe16
commit 3d01393f02
5 changed files with 96 additions and 7 deletions

View File

@@ -57,6 +57,14 @@ Matrix Matrix::Identity(std::size_t taille) {
return id;
}
Matrix Matrix::ColumnVector(std::initializer_list<Element>&& initList) {
Matrix result {initList.size(), 1};
result.m_Data = initList;
return result;
}
void Matrix::Augment(const Matrix& droite) {
assert(droite.m_Raws == m_Raws);
Matrix temp {m_Raws, m_Columns + droite.m_Columns};
@@ -76,6 +84,34 @@ void Matrix::Augment(const Matrix& droite) {
*this = temp;
}
Matrix Matrix::operator+(const Matrix& other) const {
assert(GetColumnCount() == other.GetColumnCount() && GetRawCount() == other.GetRawCount());
Matrix result = *this;
for (std::size_t i = 0; i < GetRawCount(); i++) {
for (std::size_t j = 0; j < GetColumnCount(); j++) {
result.at(i, j) += other.at(i, j);
}
}
return result;
}
Matrix Matrix::operator-(const Matrix& other) const {
assert(GetColumnCount() == other.GetColumnCount() && GetRawCount() == other.GetRawCount());
Matrix result = *this;
for (std::size_t i = 0; i < GetRawCount(); i++) {
for (std::size_t j = 0; j < GetColumnCount(); j++) {
result.at(i, j) -= other.at(i, j);
}
}
return result;
}
bool Matrix::operator==(const Matrix& other) const {
if (m_Raws != other.m_Raws || m_Columns != other.m_Columns)
return false;

View File

@@ -37,15 +37,19 @@ std::size_t Vect::GetCardinal() const {
return m_Data.GetColumnCount();
}
bool Vect::IsElementOf(const Matrix& vec) const {
Vect base = *this;
base.AddVector(vec);
return base.GetCardinal() == GetCardinal();
}
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 à l'espace vectoriel engendré par 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())
if (!IsElementOf(other.GetVector(i)))
return false;
}
return true;
@@ -78,4 +82,8 @@ std::size_t Vect::GetDimension() const {
}
VectAffine::VectAffine(const Vect& base, const Matrix& origine) :
m_Base(base), m_Origin(origine.SubMatrix(0, 0, m_Base.GetDimension(), 1)) {}
m_Base(base), m_Origin(origine.SubMatrix(0, 0, m_Base.GetDimension(), 1)) {}
bool VectAffine::IsElementOf(const Matrix& vec) const {
return m_Base.IsElementOf(vec - m_Origin);
}