This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
@@ -39,10 +40,6 @@ Matrix Matrix::operator*(const Matrix& other) const {
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool IsEqualZero(long double var) {
|
||||
return std::abs(var) < std::pow(10, -5);
|
||||
}
|
||||
|
||||
void Matrix::Print() const {
|
||||
for (size_t i = 0; i < m_Lignes; ++i) {
|
||||
std::cout << "[ ";
|
||||
@@ -101,12 +98,14 @@ void Matrix::Load(const std::string& filename) {
|
||||
}
|
||||
}
|
||||
|
||||
void Matrix::Transpose() {
|
||||
Matrix Matrix::Transpose() const {
|
||||
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++) {
|
||||
std::swap(at(i, j), at(j, i));
|
||||
result.at(j, i) = at(i, j);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void Matrix::Identity() {
|
||||
@@ -224,4 +223,25 @@ long double& Matrix::at(std::size_t ligne, std::size_t colonne) {
|
||||
|
||||
long double Matrix::at(std::size_t ligne, std::size_t colonne) const {
|
||||
return m_Data[ligne * m_Lignes + colonne];
|
||||
}
|
||||
|
||||
std::size_t Matrix::GetRawCount() const {
|
||||
return m_Lignes;
|
||||
}
|
||||
|
||||
std::size_t Matrix::GetColumnCount() const {
|
||||
return m_Colonnes;
|
||||
}
|
||||
|
||||
Matrix Matrix::SubMatrix(std::size_t origine_ligne, std::size_t origine_colonne, std::size_t ligne, std::size_t colonne) const {
|
||||
assert(m_Lignes >= ligne && m_Colonnes >= colonne);
|
||||
Matrix result{ligne, colonne};
|
||||
|
||||
for (std::size_t i = 0; i < ligne; i++) {
|
||||
for (std::size_t j = 0; j < colonne; j++) {
|
||||
result.at(i, j) = at(i + origine_ligne, j + origine_colonne);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
14
src/Matrix.h
14
src/Matrix.h
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -15,6 +17,9 @@ class Matrix {
|
||||
Matrix(std::size_t lignes, std::size_t colonnes, std::initializer_list<long double>&& initList);
|
||||
~Matrix();
|
||||
|
||||
std::size_t GetRawCount() const;
|
||||
std::size_t GetColumnCount() const;
|
||||
|
||||
Matrix operator*(const Matrix& other) const;
|
||||
|
||||
void GaussNonJordan(bool reduite);
|
||||
@@ -31,12 +36,14 @@ class Matrix {
|
||||
|
||||
void Load(const std::string& filename);
|
||||
|
||||
void Transpose();
|
||||
Matrix Transpose() const;
|
||||
|
||||
void Identity();
|
||||
|
||||
bool IsInversed() const;
|
||||
|
||||
Matrix SubMatrix(std::size_t origine_ligne, std::size_t origine_colonne, std::size_t ligne, std::size_t colonne) const;
|
||||
|
||||
bool operator==(const Matrix& other) const;
|
||||
|
||||
long double& operator[](std::size_t indice);
|
||||
@@ -46,4 +53,7 @@ class Matrix {
|
||||
long double at(std::size_t ligne, std::size_t colonne) const;
|
||||
};
|
||||
|
||||
static bool IsEqualZero(long double var);
|
||||
template <typename T>
|
||||
bool IsEqualZero(T var) {
|
||||
return std::abs(var) < std::pow(10, -5);
|
||||
}
|
||||
20
src/Vect.cpp
Normal file
20
src/Vect.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "Vect.h"
|
||||
|
||||
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)))
|
||||
break;
|
||||
}
|
||||
if (j == mat.GetRawCount()) {
|
||||
m_Data = mat.SubMatrix(0, 0, mat.GetRawCount(), j);
|
||||
}
|
||||
}
|
||||
m_Data = mat;
|
||||
}
|
||||
|
||||
// TODO
|
||||
void Vect::Print() const {
|
||||
|
||||
}
|
||||
22
src/Vect.h
Normal file
22
src/Vect.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include "Matrix.h"
|
||||
|
||||
// espace vectoriel
|
||||
class Vect {
|
||||
private:
|
||||
Matrix m_Data{0, 0};
|
||||
|
||||
public:
|
||||
/**
|
||||
* \brief Construit une base d'un espace vectoriel à partir des colonnes d'une matrice.
|
||||
* Ne prend pas en compte les colonnes de 0
|
||||
* \param mat Une matrice échelonnée.
|
||||
*/
|
||||
Vect(const Matrix& mat);
|
||||
|
||||
/**
|
||||
* \brief Affiche la base de l'espace vectoriel dans la console
|
||||
*/
|
||||
void Print() const;
|
||||
};
|
||||
@@ -4,6 +4,7 @@
|
||||
#ifdef NDEBUG
|
||||
#error "Il faut être en debug mode ! xmake f -m debug"
|
||||
#endif
|
||||
|
||||
struct Test{
|
||||
Matrix mat;
|
||||
Matrix res;
|
||||
|
||||
Reference in New Issue
Block a user