Compare commits

..

4 Commits

Author SHA1 Message Date
a016163b86 more example
All checks were successful
Linux arm64 / Build (push) Successful in 8m58s
2024-02-14 20:30:16 +01:00
d91d35a3af implement Vect 2024-02-14 20:29:25 +01:00
b90195cac1 change transpose signature 2024-02-14 20:29:02 +01:00
715bc843b2 O_o 2024-02-14 20:22:14 +01:00
5 changed files with 49 additions and 18 deletions

View File

@@ -98,14 +98,14 @@ void Matrix::Load(const std::string& filename) {
}
}
Matrix Matrix::Transpose() const {
void Matrix::Transpose() {
Matrix result{m_Colonnes, m_Lignes};
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 = 0; j < m_Colonnes; j++) {
result.at(j, i) = at(i, j);
}
}
return result;
*this = result;
}
void Matrix::Identity() {
@@ -218,11 +218,11 @@ long double& Matrix::operator[](std::size_t indice) {
}
long double& Matrix::at(std::size_t ligne, std::size_t colonne) {
return m_Data[ligne * m_Lignes + colonne];
return m_Data[ligne * m_Colonnes + colonne];
}
long double Matrix::at(std::size_t ligne, std::size_t colonne) const {
return m_Data[ligne * m_Lignes + colonne];
return m_Data[ligne * m_Colonnes + colonne];
}
std::size_t Matrix::GetRawCount() const {

View File

@@ -36,7 +36,7 @@ class Matrix {
void Load(const std::string& filename);
Matrix Transpose() const;
void Transpose();
void Identity();

View File

@@ -1,20 +1,32 @@
#include "Vect.h"
#include <iostream>
Vect::Vect(const Matrix& mat) {
for (std::size_t i = 0; i < mat.GetColumnCount(); i++) {
std::size_t j;
for (j = 0; j < mat.GetRawCount(); j++) {
if(!IsEqualZero(mat.at(i, j)))
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 (j == mat.GetRawCount()) {
if (i == mat.GetRawCount()) {
m_Data = mat.SubMatrix(0, 0, mat.GetRawCount(), j);
return;
}
}
m_Data = mat;
}
// TODO
void Vect::Print() const {
std::cout << "Espace vectoriel de dimension " << m_Data.GetColumnCount() << " 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++) {
printf("[ %.3f ]\t", static_cast<float>(m_Data.at(i, j)));
}
std::cout << "\n";
}
}

View File

@@ -5,7 +5,7 @@
// espace vectoriel
class Vect {
private:
Matrix m_Data{0, 0};
Matrix m_Data;
public:
/**
@@ -16,7 +16,10 @@ class Vect {
Vect(const Matrix& mat);
/**
* \brief Affiche la base de l'espace vectoriel dans la console
*/
* \brief Affiche la base de l'espace vectoriel dans la console
*/
void Print() const;
private:
void Simplify();
};

View File

@@ -1,4 +1,4 @@
#include "Matrix.h"
#include "Vect.h"
#include <iostream>
void test() {
@@ -15,6 +15,22 @@ void test() {
std::cout << "<<\nTransposée:\n";
mat.Print();
// 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";
mat2.Print();
Vect sol {mat2};
sol.Print();
}
void prompt() {