Compare commits
4 Commits
23de24e9a1
...
a016163b86
| Author | SHA1 | Date | |
|---|---|---|---|
| a016163b86 | |||
| d91d35a3af | |||
| b90195cac1 | |||
| 715bc843b2 |
@@ -98,14 +98,14 @@ void Matrix::Load(const std::string& filename) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix Matrix::Transpose() const {
|
void Matrix::Transpose() {
|
||||||
Matrix result{m_Colonnes, m_Lignes};
|
Matrix result{m_Colonnes, m_Lignes};
|
||||||
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 = 0; j < m_Colonnes; j++) {
|
||||||
result.at(j, i) = at(i, j);
|
result.at(j, i) = at(i, j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
*this = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix::Identity() {
|
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) {
|
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 {
|
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 {
|
std::size_t Matrix::GetRawCount() const {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class Matrix {
|
|||||||
|
|
||||||
void Load(const std::string& filename);
|
void Load(const std::string& filename);
|
||||||
|
|
||||||
Matrix Transpose() const;
|
void Transpose();
|
||||||
|
|
||||||
void Identity();
|
void Identity();
|
||||||
|
|
||||||
|
|||||||
28
src/Vect.cpp
28
src/Vect.cpp
@@ -1,20 +1,32 @@
|
|||||||
#include "Vect.h"
|
#include "Vect.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
Vect::Vect(const Matrix& mat) {
|
Vect::Vect(const Matrix& mat) : m_Data(mat) {
|
||||||
for (std::size_t i = 0; i < mat.GetColumnCount(); i++) {
|
Simplify();
|
||||||
std::size_t j;
|
}
|
||||||
for (j = 0; j < mat.GetRawCount(); j++) {
|
|
||||||
if(!IsEqualZero(mat.at(i, j)))
|
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;
|
break;
|
||||||
}
|
}
|
||||||
if (j == mat.GetRawCount()) {
|
if (i == mat.GetRawCount()) {
|
||||||
m_Data = mat.SubMatrix(0, 0, mat.GetRawCount(), j);
|
m_Data = mat.SubMatrix(0, 0, mat.GetRawCount(), j);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_Data = mat;
|
m_Data = mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
|
||||||
void Vect::Print() const {
|
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";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
// espace vectoriel
|
// espace vectoriel
|
||||||
class Vect {
|
class Vect {
|
||||||
private:
|
private:
|
||||||
Matrix m_Data{0, 0};
|
Matrix m_Data;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@@ -16,7 +16,10 @@ class Vect {
|
|||||||
Vect(const Matrix& mat);
|
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;
|
void Print() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void Simplify();
|
||||||
};
|
};
|
||||||
18
src/main.cpp
18
src/main.cpp
@@ -1,4 +1,4 @@
|
|||||||
#include "Matrix.h"
|
#include "Vect.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
void test() {
|
void test() {
|
||||||
@@ -15,6 +15,22 @@ void test() {
|
|||||||
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"};
|
||||||
|
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() {
|
void prompt() {
|
||||||
|
|||||||
Reference in New Issue
Block a user