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};
|
||||
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 {
|
||||
|
||||
@@ -36,7 +36,7 @@ class Matrix {
|
||||
|
||||
void Load(const std::string& filename);
|
||||
|
||||
Matrix Transpose() const;
|
||||
void Transpose();
|
||||
|
||||
void Identity();
|
||||
|
||||
|
||||
26
src/Vect.cpp
26
src/Vect.cpp
@@ -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++) {
|
||||
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";
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
// espace vectoriel
|
||||
class Vect {
|
||||
private:
|
||||
Matrix m_Data{0, 0};
|
||||
Matrix m_Data;
|
||||
|
||||
public:
|
||||
/**
|
||||
@@ -19,4 +19,7 @@ class Vect {
|
||||
* \brief Affiche la base de l'espace vectoriel dans la console
|
||||
*/
|
||||
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>
|
||||
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user