Merge branch 'master' into imgui
All checks were successful
Linux arm64 / Build (push) Successful in 3m16s
All checks were successful
Linux arm64 / Build (push) Successful in 3m16s
This commit is contained in:
142
src/Gauss.cpp
142
src/Gauss.cpp
@@ -2,74 +2,112 @@
|
||||
|
||||
#include "Matrix.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <execution>
|
||||
#include <ranges>
|
||||
|
||||
namespace Gauss {
|
||||
|
||||
static void GaussNonJordan(Matrix& mat, bool reduite) {
|
||||
int r = -1;
|
||||
for (std::size_t j = 0; j < mat.GetColumnCount(); j++) {
|
||||
std::size_t indice_ligne_maximum = r + 1;
|
||||
static void SwapLines(Matrix& mat, std::size_t line1, std::size_t line2) {
|
||||
std::swap_ranges(
|
||||
std::execution::par_unseq, mat.GetLineIterator(line1), mat.GetLineIterator(line1 + 1), mat.GetLineIterator(line2));
|
||||
}
|
||||
|
||||
// Recherche maximum
|
||||
for (std::size_t i = r + 1; i < mat.GetRawCount(); i++) {
|
||||
if (std::abs(mat.at(i, j)) > std::abs(mat.at(indice_ligne_maximum, j)))
|
||||
indice_ligne_maximum = i;
|
||||
static void DivideLine(Matrix& mat, std::size_t line, Matrix::Element number) {
|
||||
std::transform(std::execution::par_unseq, mat.GetLineIterator(line), mat.GetLineIterator(line + 1), mat.GetLineIterator(line),
|
||||
[number](Matrix::Element e) { return e /= number; });
|
||||
}
|
||||
|
||||
static int FirstNotNullElementIndexOnColumn(Matrix& mat, std::size_t column, std::size_t startLine = 0) {
|
||||
for (std::size_t i = startLine; i < mat.GetRawCount(); i++) {
|
||||
if (!IsEqualZero(mat.at(i, column))) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void SimplifyLine(Matrix& mat, std::size_t line, std::size_t pivot_line, std::size_t pivot_column) {
|
||||
const Matrix::Element pivot = mat.at(pivot_line, pivot_column);
|
||||
const Matrix::Element anul = mat.at(line, pivot_column);
|
||||
|
||||
auto range = std::views::iota(static_cast<std::size_t>(0), mat.GetColumnCount());
|
||||
|
||||
std::for_each(std::execution::par_unseq, range.begin(), range.end(), [&mat, pivot, anul, line, pivot_line](std::size_t j) {
|
||||
mat.at(line, j) = mat.at(line, j) * pivot - mat.at(pivot_line, j) * anul;
|
||||
});
|
||||
}
|
||||
|
||||
static void GaussJordanReduced(Matrix& a_Matrix, bool a_Normalise) {
|
||||
int indice_ligne_pivot = -1;
|
||||
|
||||
for (std::size_t j = 0; j < a_Matrix.GetColumnCount(); j++) {
|
||||
|
||||
int indice_ligne_pivot_trouve = FirstNotNullElementIndexOnColumn(a_Matrix, j, indice_ligne_pivot + 1);
|
||||
|
||||
if (indice_ligne_pivot_trouve < 0) // colonne de 0
|
||||
continue; // on regarde la prochaine colonne
|
||||
|
||||
indice_ligne_pivot++;
|
||||
|
||||
if (indice_ligne_pivot_trouve != indice_ligne_pivot) {
|
||||
SwapLines(a_Matrix, indice_ligne_pivot_trouve, indice_ligne_pivot);
|
||||
}
|
||||
|
||||
// Si A[k,j]≠0 alors (A[k,j] désigne la valeur de la ligne k et de la colonne j)
|
||||
if (!IsEqualZero(mat.at(indice_ligne_maximum, j))) {
|
||||
r++;
|
||||
Matrix::Element pivot = a_Matrix.at(indice_ligne_pivot, j);
|
||||
|
||||
// Si k≠r alors
|
||||
if (indice_ligne_maximum != r) {
|
||||
// Échanger les lignes k et r (On place la ligne du pivot en position r)
|
||||
for (std::size_t k = 0; k < mat.GetColumnCount(); k++) {
|
||||
std::swap(mat.at(indice_ligne_maximum, k), mat.at(r, k));
|
||||
}
|
||||
}
|
||||
|
||||
// Pour i de 1 jusqu'à n (On simplifie les autres lignes)
|
||||
for (std::size_t i = (reduite ? 0 : j); i < mat.GetRawCount(); i++) {
|
||||
// Si i≠r alors
|
||||
if (i != r) {
|
||||
// Soustraire à la ligne i la ligne r multipliée par A[i,j] (de façon à
|
||||
// annuler A[i,j])
|
||||
for (int k = mat.GetColumnCount() - 1; k >= 0; k--) {
|
||||
long double pivot = mat.at(r, j);
|
||||
long double anul = mat.at(i, j);
|
||||
mat.at(i, k) = mat.at(i, k) * pivot - mat.at(r, k) * anul;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (a_Normalise) {
|
||||
DivideLine(a_Matrix, indice_ligne_pivot, pivot);
|
||||
}
|
||||
|
||||
auto range = std::views::iota(static_cast<std::size_t>(0), a_Matrix.GetRawCount());
|
||||
|
||||
// On simplifie les autres lignes
|
||||
std::for_each(std::execution::par_unseq, range.begin(), range.end(), [&a_Matrix, j, indice_ligne_pivot](std::size_t i) {
|
||||
if (i != static_cast<std::size_t>(indice_ligne_pivot)) {
|
||||
SimplifyLine(a_Matrix, i, indice_ligne_pivot, j);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static void GaussJordan(Matrix& mat, bool reduite) {
|
||||
GaussNonJordan(mat, reduite);
|
||||
for (std::size_t i = 0; i < mat.GetRawCount(); i++) {
|
||||
int k = -1;
|
||||
for (std::size_t j = 0; j < mat.GetColumnCount(); j++) {
|
||||
if (!IsEqualZero(mat.at(i, j))) {
|
||||
k = j;
|
||||
break;
|
||||
}
|
||||
static void GaussJordanTriangular(Matrix& a_Matrix, bool a_Normalise) {
|
||||
int indice_ligne_pivot = -1;
|
||||
|
||||
for (std::size_t j = 0; j < a_Matrix.GetColumnCount(); j++) {
|
||||
|
||||
int indice_ligne_pivot_trouve = FirstNotNullElementIndexOnColumn(a_Matrix, j, indice_ligne_pivot + 1);
|
||||
|
||||
if (indice_ligne_pivot_trouve < 0) // colonne de 0
|
||||
continue; // on regarde la prochaine colonne
|
||||
|
||||
indice_ligne_pivot++;
|
||||
|
||||
if (indice_ligne_pivot_trouve != indice_ligne_pivot) {
|
||||
SwapLines(a_Matrix, indice_ligne_pivot_trouve, indice_ligne_pivot);
|
||||
}
|
||||
// ligne de 0
|
||||
if (k == -1)
|
||||
break;
|
||||
// on divise la ligne par (i, k)
|
||||
long double annul = mat.at(i, k);
|
||||
for (int j = 0; j < mat.GetColumnCount(); j++) {
|
||||
mat.at(i, j) /= annul;
|
||||
|
||||
Matrix::Element pivot = a_Matrix.at(indice_ligne_pivot, j);
|
||||
|
||||
if (a_Normalise) {
|
||||
DivideLine(a_Matrix, indice_ligne_pivot, pivot);
|
||||
}
|
||||
|
||||
auto range = std::views::iota(static_cast<std::size_t>(indice_ligne_pivot + 1), a_Matrix.GetRawCount());
|
||||
|
||||
// On simplifie les autres lignes après la ligne du pivot
|
||||
std::for_each(std::execution::par_unseq, range.begin(), range.end(),
|
||||
[&a_Matrix, indice_ligne_pivot, j](std::size_t i) {
|
||||
SimplifyLine(a_Matrix, i, indice_ligne_pivot, j);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void GaussJordan(Matrix& mat, bool reduite, bool normalise) {
|
||||
if (normalise)
|
||||
GaussJordan(mat, reduite);
|
||||
void GaussJordan(Matrix& a_Matrix, bool a_Reduite, bool a_Normalise) {
|
||||
if (a_Reduite)
|
||||
GaussJordanReduced(a_Matrix, a_Normalise);
|
||||
else
|
||||
GaussNonJordan(mat, reduite);
|
||||
GaussJordanTriangular(a_Matrix, a_Normalise);
|
||||
}
|
||||
|
||||
} // namespace Gauss
|
||||
@@ -1,9 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class Matrix;
|
||||
|
||||
namespace Gauss {
|
||||
|
||||
void GaussJordan(Matrix& mat, bool reduite, bool normalise);
|
||||
|
||||
} // namespace Gauss
|
||||
101
src/IO.cpp
Normal file
101
src/IO.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
#include "IO.h"
|
||||
|
||||
#include "Vect.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
std::ostream& operator<<(std::ostream& stream, const Matrix& mat) {
|
||||
stream << mat.GetRawCount() << " " << mat.GetColumnCount() << "\n";
|
||||
for (std::size_t i = 0; i < mat.GetRawCount(); i++) {
|
||||
for (std::size_t j = 0; j < mat.GetColumnCount(); j++) {
|
||||
stream << mat.at(i, j) << " ";
|
||||
}
|
||||
stream << "\n";
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
|
||||
std::istream& operator>>(std::istream& stream, Matrix& mat) {
|
||||
std::size_t raw, column;
|
||||
stream >> raw >> column;
|
||||
|
||||
Matrix result {raw, column};
|
||||
mat = result;
|
||||
|
||||
for (std::size_t i = 0; i < mat.GetRawCount(); i++) {
|
||||
for (std::size_t j = 0; j < mat.GetColumnCount(); j++) {
|
||||
stream >> mat.at(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
Matrix LoadMatrix(const std::string& fileName) {
|
||||
std::ifstream in {fileName};
|
||||
if (!in) {
|
||||
std::cerr << "Impossible de charger la matrice !\n";
|
||||
return {};
|
||||
}
|
||||
Matrix result;
|
||||
in >> result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void SaveMatrix(const Matrix& mat, const std::string& fileName) {
|
||||
std::ofstream out {fileName};
|
||||
if (!out) {
|
||||
std::cerr << "Impossible de sauvegarder la matrice !\n";
|
||||
return;
|
||||
}
|
||||
out << mat;
|
||||
}
|
||||
|
||||
Matrix InsertMatrix() {
|
||||
std::cout << "Quelle est le nombre de lignes de votre matrice ?" << std::endl;
|
||||
std::size_t lignes;
|
||||
std::cin >> lignes;
|
||||
std::cout << "Quelle est le nombre de colonnes de votre matrice ?" << std::endl;
|
||||
std::size_t colonnes;
|
||||
std::cin >> colonnes;
|
||||
std::cout << "Rentrez les coefficients de la matrice" << std::endl;
|
||||
Matrix result(lignes, colonnes);
|
||||
for (size_t i = 0; i < result.GetRawCount(); ++i) {
|
||||
for (size_t j = 0; j < result.GetColumnCount(); ++j) {
|
||||
std::cin >> result.at(i, j);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Print(const Matrix& mat) {
|
||||
for (size_t i = 0; i < mat.GetRawCount(); ++i) {
|
||||
std::cout << "[ ";
|
||||
for (size_t j = 0; j < mat.GetColumnCount(); ++j) {
|
||||
std::cout << mat.at(i, j) << " ";
|
||||
}
|
||||
std::cout << "]";
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Print(const Vect& vect) {
|
||||
std::cout << "Espace vectoriel de dimension " << vect.GetCardinal() << " de base :\n\n";
|
||||
for (std::size_t i = 0; i < vect.GetDimension(); i++) {
|
||||
for (std::size_t j = 0; j < vect.GetCardinal(); j++) {
|
||||
Matrix vector = vect.GetVector(j);
|
||||
std::cout << "[ " << vector.at(i, 0) << " ]\t";
|
||||
}
|
||||
std::cout << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void Print(const VectAffine& vect) {
|
||||
std::cout << "\tEspace Affine :\n\n";
|
||||
Print(vect.GetBase());
|
||||
std::cout << "\nOrigine :\n\n";
|
||||
Print(vect.GetOrigin());
|
||||
}
|
||||
217
src/Matrix.cpp
217
src/Matrix.cpp
@@ -1,40 +1,32 @@
|
||||
#include "Matrix.h"
|
||||
|
||||
#include "IO.h"
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
Matrix::Matrix(const std::string& fileNameInput) {
|
||||
Load(fileNameInput);
|
||||
}
|
||||
|
||||
Matrix::Matrix(std::size_t lignes, std::size_t colonnes) : m_Raws(lignes), m_Columns(colonnes) {
|
||||
Matrix::Matrix(std::size_t a_Raws, std::size_t a_Columns) : m_Raws(a_Raws), m_Columns(a_Columns) {
|
||||
m_Data.resize(m_Raws * m_Columns);
|
||||
}
|
||||
|
||||
Matrix::Matrix(std::size_t lignes, std::size_t colonnes, std::initializer_list<long double>&& initList) :
|
||||
m_Raws(lignes), m_Columns(colonnes) {
|
||||
m_Data = initList;
|
||||
Matrix::Matrix(std::size_t a_Raws, std::size_t a_Columns, std::initializer_list<Element>&& a_Elements) :
|
||||
m_Raws(a_Raws), m_Columns(a_Columns) {
|
||||
m_Data = a_Elements;
|
||||
m_Data.resize(m_Raws * m_Columns);
|
||||
}
|
||||
|
||||
Matrix::~Matrix() {}
|
||||
Matrix Matrix::operator*(const Matrix& a_Other) const {
|
||||
assert(m_Columns == a_Other.m_Raws);
|
||||
|
||||
Matrix Matrix::operator*(const Matrix& other) const {
|
||||
if (m_Columns != other.m_Raws) {
|
||||
std::cerr << "Mutiplication impossible car la dimensions des matrices est incompatible" << std::endl;
|
||||
return {1, 1, {0}};
|
||||
}
|
||||
|
||||
Matrix result(m_Raws, other.m_Columns);
|
||||
Matrix result(m_Raws, a_Other.m_Columns);
|
||||
|
||||
for (std::size_t i = 0; i < m_Raws; ++i) {
|
||||
for (std::size_t j = 0; j < other.m_Columns; ++j) {
|
||||
long double sum = 0;
|
||||
for (std::size_t j = 0; j < a_Other.m_Columns; ++j) {
|
||||
Element sum = 0;
|
||||
for (std::size_t k = 0; k < m_Columns; k++) {
|
||||
sum += at(i, k) * other.at(k, j);
|
||||
sum += at(i, k) * a_Other.at(k, j);
|
||||
}
|
||||
result.at(i, j) = sum;
|
||||
}
|
||||
@@ -42,45 +34,6 @@ Matrix Matrix::operator*(const Matrix& other) const {
|
||||
return result;
|
||||
}
|
||||
|
||||
void Matrix::Print() const {
|
||||
for (size_t i = 0; i < m_Raws; ++i) {
|
||||
std::cout << "[ ";
|
||||
for (size_t j = 0; j < m_Columns; ++j) {
|
||||
std::size_t indice = i * m_Raws + j;
|
||||
std::cout << at(i, j) << " ";
|
||||
}
|
||||
std::cout << "]";
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Matrix::Insert() {
|
||||
for (size_t i = 0; i < m_Raws; ++i) {
|
||||
for (size_t j = 0; j < m_Columns; ++j) {
|
||||
std::cin >> at(i, j);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Matrix::Save(const std::string& fileName) {
|
||||
std::ofstream out {fileName};
|
||||
if (!out) {
|
||||
std::cerr << "Impossible de sauvegarder la matrice !\n";
|
||||
return;
|
||||
}
|
||||
out << *this;
|
||||
}
|
||||
|
||||
void Matrix::Load(const std::string& filename) {
|
||||
std::ifstream in {filename};
|
||||
if (!in) {
|
||||
std::cerr << "Impossible de charger la matrice !\n";
|
||||
return;
|
||||
}
|
||||
in >> *this;
|
||||
}
|
||||
|
||||
void Matrix::Transpose() {
|
||||
Matrix result {m_Columns, m_Raws};
|
||||
for (std::size_t i = 0; i < m_Raws; i++) {
|
||||
@@ -91,19 +44,43 @@ void Matrix::Transpose() {
|
||||
*this = result;
|
||||
}
|
||||
|
||||
Matrix Matrix::Identity(std::size_t taille) {
|
||||
Matrix id {taille, taille};
|
||||
for (std::size_t i = 0; i < taille; i++) {
|
||||
for (std::size_t j = i; j < taille; j++) {
|
||||
Matrix Matrix::Identity(std::size_t a_Size) {
|
||||
Matrix id {a_Size, a_Size};
|
||||
for (std::size_t i = 0; i < a_Size; i++) {
|
||||
for (std::size_t j = i; j < a_Size; j++) {
|
||||
id.at(i, j) = (i == j);
|
||||
}
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
void Matrix::Augment(const Matrix& droite) {
|
||||
assert(droite.m_Raws == m_Raws);
|
||||
Matrix temp {m_Raws, m_Columns + droite.m_Columns};
|
||||
Matrix Matrix::ColumnVector(std::initializer_list<Element>&& a_Elements) {
|
||||
Matrix result {a_Elements.size(), 1};
|
||||
|
||||
result.m_Data = a_Elements;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Matrix Matrix::RawVector(std::initializer_list<Element>&& a_Elements) {
|
||||
Matrix result {1, a_Elements.size()};
|
||||
|
||||
result.m_Data = a_Elements;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Matrix::Fill(Element a_Element) {
|
||||
for (std::size_t i = 0; i < m_Raws; i++) {
|
||||
for (std::size_t j = 0; j < m_Columns; j++) {
|
||||
at(i, j) = a_Element;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Matrix::Augment(const Matrix& a_Right) {
|
||||
assert(a_Right.m_Raws == m_Raws);
|
||||
Matrix temp {m_Raws, m_Columns + a_Right.m_Columns};
|
||||
|
||||
for (std::size_t i = 0; i < m_Raws; i++) {
|
||||
for (std::size_t j = 0; j < m_Columns; j++) {
|
||||
@@ -112,21 +89,67 @@ void Matrix::Augment(const Matrix& droite) {
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < m_Raws; i++) {
|
||||
for (std::size_t j = 0; j < droite.m_Columns; j++) {
|
||||
temp.at(i, j + m_Columns) = droite.at(i, j);
|
||||
for (std::size_t j = 0; j < a_Right.m_Columns; j++) {
|
||||
temp.at(i, j + m_Columns) = a_Right.at(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
*this = temp;
|
||||
}
|
||||
|
||||
bool Matrix::operator==(const Matrix& other) const {
|
||||
if (m_Raws != other.m_Raws || m_Columns != other.m_Columns)
|
||||
return false;
|
||||
void Matrix::AugmentBottom(const Matrix& a_Bottom) {
|
||||
assert(a_Bottom.m_Columns == m_Columns);
|
||||
Matrix temp {m_Raws + a_Bottom.GetRawCount(), m_Columns};
|
||||
|
||||
for (std::size_t i = 0; i < m_Raws; i++) {
|
||||
for (std::size_t j = 0; j < m_Columns; j++) {
|
||||
if (!IsEqualZero(at(i, j) - other.at(i, j)))
|
||||
temp.at(i, j) = at(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
for (std::size_t i = 0; i < a_Bottom.GetRawCount(); i++) {
|
||||
for (std::size_t j = 0; j < GetColumnCount(); j++) {
|
||||
temp.at(i + GetRawCount(), j) = a_Bottom.at(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
*this = temp;
|
||||
}
|
||||
|
||||
Matrix Matrix::operator+(const Matrix& a_Other) const {
|
||||
assert(GetColumnCount() == a_Other.GetColumnCount() && GetRawCount() == a_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) += a_Other.at(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Matrix Matrix::operator-(const Matrix& a_Other) const {
|
||||
assert(GetColumnCount() == a_Other.GetColumnCount() && GetRawCount() == a_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) -= a_Other.at(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Matrix::operator==(const Matrix& a_Other) const {
|
||||
assert(m_Raws == a_Other.m_Raws && m_Columns == a_Other.m_Columns);
|
||||
|
||||
for (std::size_t i = 0; i < m_Raws; i++) {
|
||||
for (std::size_t j = 0; j < m_Columns; j++) {
|
||||
if (!IsEqualZero(at(i, j) - a_Other.at(i, j)))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -134,16 +157,12 @@ bool Matrix::operator==(const Matrix& other) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
long double& Matrix::operator[](std::size_t indice) {
|
||||
return m_Data[indice];
|
||||
Matrix::Element& Matrix::at(std::size_t a_Raw, std::size_t a_Column) {
|
||||
return m_Data[a_Raw * m_Columns + a_Column];
|
||||
}
|
||||
|
||||
long double& Matrix::at(std::size_t ligne, std::size_t colonne) {
|
||||
return m_Data[ligne * m_Columns + colonne];
|
||||
}
|
||||
|
||||
long double Matrix::at(std::size_t ligne, std::size_t colonne) const {
|
||||
return m_Data[ligne * m_Columns + colonne];
|
||||
Matrix::Element Matrix::at(std::size_t a_Raw, std::size_t a_Column) const {
|
||||
return m_Data[a_Raw * m_Columns + a_Column];
|
||||
}
|
||||
|
||||
std::size_t Matrix::GetRawCount() const {
|
||||
@@ -154,37 +173,29 @@ std::size_t Matrix::GetColumnCount() const {
|
||||
return m_Columns;
|
||||
}
|
||||
|
||||
Matrix Matrix::SubMatrix(std::size_t origine_ligne, std::size_t origine_colonne, std::size_t ligne, std::size_t colonne) const {
|
||||
assert(m_Raws >= ligne && m_Columns >= colonne);
|
||||
Matrix result {ligne, colonne};
|
||||
Matrix Matrix::SubMatrix(
|
||||
std::size_t a_RawOrigin, std::size_t a_ColumnOrigin, std::size_t a_RawCount, std::size_t a_ColumnCount) const {
|
||||
assert(m_Raws >= a_RawOrigin + a_RawCount && m_Columns >= a_ColumnOrigin + a_ColumnCount);
|
||||
|
||||
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);
|
||||
Matrix result {a_RawCount, a_ColumnCount};
|
||||
|
||||
for (std::size_t i = 0; i < result.GetRawCount(); i++) {
|
||||
for (std::size_t j = 0; j < result.GetColumnCount(); j++) {
|
||||
result.at(i, j) = at(i + a_RawOrigin, j + a_ColumnOrigin);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& stream, const Matrix& mat) {
|
||||
stream << mat.m_Raws << " " << mat.m_Columns << "\n";
|
||||
for (std::size_t i = 0; i < mat.m_Raws; i++) {
|
||||
for (std::size_t j = 0; j < mat.m_Columns; j++) {
|
||||
stream << mat.at(i, j) << " ";
|
||||
}
|
||||
stream << "\n";
|
||||
}
|
||||
return stream;
|
||||
Matrix::iterator Matrix::begin() {
|
||||
return m_Data.begin();
|
||||
}
|
||||
|
||||
std::istream& operator>>(std::istream& stream, Matrix& mat) {
|
||||
stream >> mat.m_Raws >> mat.m_Columns;
|
||||
mat.m_Data.resize(mat.m_Raws * mat.m_Columns);
|
||||
for (std::size_t i = 0; i < mat.m_Raws; i++) {
|
||||
for (std::size_t j = 0; j < mat.m_Columns; j++) {
|
||||
stream >> mat.at(i, j);
|
||||
}
|
||||
}
|
||||
return stream;
|
||||
Matrix::iterator Matrix::end() {
|
||||
return m_Data.end();
|
||||
}
|
||||
|
||||
Matrix::iterator Matrix::GetLineIterator(std::size_t a_Raw) {
|
||||
return m_Data.begin() + a_Raw * GetColumnCount();
|
||||
}
|
||||
51
src/Matrix.h
51
src/Matrix.h
@@ -1,51 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class Matrix {
|
||||
private:
|
||||
std::size_t m_Raws;
|
||||
std::size_t m_Columns;
|
||||
std::vector<long double> m_Data;
|
||||
|
||||
public:
|
||||
Matrix(const std::string& fileNameInput);
|
||||
Matrix(std::size_t raws, std::size_t columns);
|
||||
Matrix(std::size_t raws, std::size_t columns, std::initializer_list<long double>&& initList);
|
||||
~Matrix();
|
||||
|
||||
std::size_t GetRawCount() const;
|
||||
std::size_t GetColumnCount() const;
|
||||
|
||||
void Insert();
|
||||
void Print() const;
|
||||
|
||||
void Save(const std::string& fileName);
|
||||
void Load(const std::string& filename);
|
||||
|
||||
void Transpose();
|
||||
|
||||
static Matrix Identity(std::size_t size);
|
||||
|
||||
void Augment(const Matrix& right);
|
||||
|
||||
Matrix SubMatrix(std::size_t raw_origin, std::size_t column_origin, std::size_t raw, std::size_t column) const;
|
||||
|
||||
bool operator==(const Matrix& other) const;
|
||||
Matrix operator*(const Matrix& other) const;
|
||||
long double& operator[](std::size_t index);
|
||||
|
||||
long double& at(std::size_t raw, std::size_t column);
|
||||
long double at(std::size_t raw, std::size_t column) const;
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& stream, const Matrix& mat);
|
||||
friend std::istream& operator>>(std::istream& stream, Matrix& mat);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
bool IsEqualZero(T var) {
|
||||
return std::abs(var) < std::pow(10, -5);
|
||||
}
|
||||
136
src/NR.cpp
Normal file
136
src/NR.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
#include "NR.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
int PGCD(int x, int y) {
|
||||
if (x == 0 || y == 0)
|
||||
return 1;
|
||||
else if (x % y == 0)
|
||||
return std::abs(y);
|
||||
else
|
||||
return PGCD(y, x % y);
|
||||
}
|
||||
|
||||
NR::NR() : m_Numerator(0), m_Denominator(1) {}
|
||||
|
||||
NR::NR(int entier) : m_Numerator(entier), m_Denominator(1) {}
|
||||
|
||||
NR::NR(int numerator, int denominator) :
|
||||
m_Numerator((denominator > 0) ? numerator : -numerator), m_Denominator(std::abs(denominator)) {
|
||||
assert(denominator != 0);
|
||||
Reduce();
|
||||
}
|
||||
|
||||
void NR::Reduce() {
|
||||
int divisor = PGCD(m_Denominator, m_Numerator);
|
||||
m_Denominator /= divisor;
|
||||
m_Numerator /= divisor;
|
||||
}
|
||||
|
||||
NR NR::Inverse() const {
|
||||
assert(*this != 0);
|
||||
return {m_Denominator, m_Numerator};
|
||||
}
|
||||
|
||||
int NR::GetNumerator() const {
|
||||
return m_Numerator;
|
||||
}
|
||||
|
||||
int NR::GetDenominator() const {
|
||||
return m_Denominator;
|
||||
}
|
||||
|
||||
bool NR::operator==(const NR& opNR) const {
|
||||
return (m_Numerator * opNR.GetDenominator() == m_Denominator * opNR.GetNumerator());
|
||||
}
|
||||
|
||||
bool NR::operator<(const NR& opNR) const {
|
||||
return (m_Numerator * opNR.GetDenominator() < m_Denominator * opNR.GetNumerator());
|
||||
}
|
||||
|
||||
bool NR::operator>(const NR& opNR) const {
|
||||
return (m_Numerator * opNR.GetDenominator() > m_Denominator * opNR.GetNumerator());
|
||||
}
|
||||
|
||||
bool NR::operator!=(const NR& opNR) const {
|
||||
return !(*this == opNR);
|
||||
}
|
||||
|
||||
bool NR::operator<=(const NR& opNR) const {
|
||||
return !(*this > opNR);
|
||||
}
|
||||
|
||||
bool NR::operator>=(const NR& opNR) const {
|
||||
return !(*this < opNR);
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const NR& opNR) {
|
||||
os << opNR.GetNumerator() << "/" << opNR.GetDenominator();
|
||||
return os;
|
||||
}
|
||||
|
||||
std::istream& operator>>(std::istream& is, NR& opNR) {
|
||||
char slash;
|
||||
is >> opNR.m_Numerator >> slash >> opNR.m_Denominator;
|
||||
opNR.Reduce();
|
||||
return is;
|
||||
}
|
||||
|
||||
NR NR::operator+(const NR& opNR) const {
|
||||
int num, den;
|
||||
num = m_Numerator * opNR.GetDenominator();
|
||||
den = m_Denominator * opNR.GetDenominator();
|
||||
num += (opNR.GetNumerator() * m_Denominator);
|
||||
NR result(num, den);
|
||||
return result;
|
||||
}
|
||||
|
||||
NR NR::operator-(const NR& opNR) const {
|
||||
int num, den;
|
||||
num = m_Numerator * opNR.GetDenominator();
|
||||
den = m_Denominator * opNR.GetDenominator();
|
||||
num -= (opNR.GetNumerator() * m_Denominator);
|
||||
NR result(num, den);
|
||||
return result;
|
||||
}
|
||||
|
||||
NR NR::operator*(const NR& opNR) const {
|
||||
int num, den;
|
||||
num = m_Numerator * opNR.GetNumerator();
|
||||
den = m_Denominator * opNR.GetDenominator();
|
||||
NR result(num, den);
|
||||
return result;
|
||||
}
|
||||
|
||||
NR NR::operator/(const NR& opNR) const {
|
||||
int num, den;
|
||||
num = m_Numerator * opNR.GetDenominator();
|
||||
den = m_Denominator * opNR.GetNumerator();
|
||||
NR result(num, den);
|
||||
return result;
|
||||
}
|
||||
|
||||
NR& NR::operator+=(const NR& opNR) {
|
||||
*this = *this + opNR;
|
||||
return *this;
|
||||
}
|
||||
|
||||
NR& NR::operator-=(const NR& opNR) {
|
||||
*this = *this - opNR;
|
||||
return *this;
|
||||
}
|
||||
|
||||
NR& NR::operator*=(const NR& opNR) {
|
||||
*this = *this * opNR;
|
||||
return *this;
|
||||
}
|
||||
|
||||
NR& NR::operator/=(const NR& opNR) {
|
||||
*this = *this / opNR;
|
||||
return *this;
|
||||
}
|
||||
|
||||
NR NR::operator-() const {
|
||||
return {-m_Numerator, m_Denominator};
|
||||
}
|
||||
14
src/NR.h
14
src/NR.h
@@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class NR {
|
||||
private:
|
||||
int m_Numerator;
|
||||
int m_Denominator;
|
||||
|
||||
public:
|
||||
NR() : m_Numerator(0), m_Denominator(1) {}
|
||||
|
||||
NR(int entier) : m_Numerator(entier), m_Denominator(1) {}
|
||||
|
||||
NR(int numerator, int denominator) : m_Numerator(numerator), m_Denominator(denominator) {}
|
||||
};
|
||||
@@ -2,44 +2,54 @@
|
||||
|
||||
#include "Gauss.h"
|
||||
|
||||
Solver::Solver(const Matrix& mat) : m_Matrix(mat) {}
|
||||
|
||||
Vect Solver::Image() const {
|
||||
Matrix result = m_Matrix;
|
||||
result.Transpose();
|
||||
Gauss::GaussJordan(result, true, true);
|
||||
result.Transpose();
|
||||
return {result};
|
||||
Vect Solver::Image(Matrix&& a_Matrix) const {
|
||||
a_Matrix.Transpose();
|
||||
Gauss::GaussJordan(a_Matrix, false, false);
|
||||
a_Matrix.Transpose();
|
||||
return {std::move(a_Matrix)};
|
||||
}
|
||||
|
||||
// https://en.wikipedia.org/wiki/Kernel_(linear_algebra)#Computation_by_Gaussian_elimination
|
||||
Vect Solver::Kernel() const {
|
||||
Matrix result = m_Matrix;
|
||||
result.Transpose();
|
||||
result.Augment(Matrix::Identity(result.GetRawCount()));
|
||||
Gauss::GaussJordan(result, true, true);
|
||||
result.Transpose();
|
||||
Vect Solver::Kernel(Matrix&& a_Matrix) const {
|
||||
std::size_t matrixRawCount = a_Matrix.GetRawCount();
|
||||
std::size_t matrixColumnCount = a_Matrix.GetColumnCount();
|
||||
|
||||
a_Matrix.Transpose();
|
||||
a_Matrix.Augment(Matrix::Identity(a_Matrix.GetRawCount()));
|
||||
Gauss::GaussJordan(a_Matrix, false, true);
|
||||
a_Matrix.Transpose();
|
||||
|
||||
// nombre de colonnes non nulles
|
||||
std::size_t origine_colonne = Vect(result.SubMatrix(0, 0, m_Matrix.GetRawCount(), m_Matrix.GetColumnCount())).GetCardinal();
|
||||
std::size_t origine_colonne = Vect(a_Matrix.SubMatrix(0, 0, matrixRawCount, matrixColumnCount)).GetCardinal();
|
||||
|
||||
return {result.SubMatrix(m_Matrix.GetRawCount(), origine_colonne, result.GetRawCount() - m_Matrix.GetRawCount(),
|
||||
result.GetColumnCount() - origine_colonne)};
|
||||
return {a_Matrix.SubMatrix(
|
||||
matrixRawCount, origine_colonne, a_Matrix.GetRawCount() - matrixRawCount, a_Matrix.GetColumnCount() - origine_colonne)};
|
||||
}
|
||||
|
||||
VectAffine Solver::TriangularSystem() const {
|
||||
Matrix mat = m_Matrix;
|
||||
VectAffine Solver::RectangularSystem(Matrix&& a_MatrixA, const Matrix& a_VectorB) const {
|
||||
Matrix mat = a_MatrixA;
|
||||
mat.Augment(a_VectorB);
|
||||
Gauss::GaussJordan(mat, true, true);
|
||||
|
||||
Solver solver {mat.SubMatrix(0, 0, mat.GetRawCount(), mat.GetColumnCount() - 1)};
|
||||
Solver solver;
|
||||
|
||||
Vect noyau = solver.Kernel();
|
||||
Vect noyau = solver.Kernel(std::move(a_MatrixA));
|
||||
Matrix origin = mat.SubMatrix(0, mat.GetColumnCount() - 1, mat.GetRawCount(), 1);
|
||||
|
||||
return {noyau, origin};
|
||||
// on rajoute des 0 si il faut
|
||||
|
||||
Matrix fullOrigin {mat.GetColumnCount() - 1, 1};
|
||||
for (std::size_t i = 0; i < mat.GetRawCount(); i++) {
|
||||
fullOrigin.at(i, 0) = origin.at(i, 0);
|
||||
}
|
||||
|
||||
for (std::size_t i = mat.GetRawCount(); i < mat.GetColumnCount() - 1; i++) {
|
||||
fullOrigin.at(i, 0) = 0;
|
||||
}
|
||||
|
||||
return {noyau, fullOrigin};
|
||||
}
|
||||
|
||||
std::size_t Solver::Rank() const {
|
||||
Vect image = Image();
|
||||
return image.GetCardinal();
|
||||
std::size_t Solver::Rank(Matrix&& a_Matrix) const {
|
||||
return Image(std::move(a_Matrix)).GetCardinal();
|
||||
}
|
||||
|
||||
20
src/Solver.h
20
src/Solver.h
@@ -1,20 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Vect.h"
|
||||
|
||||
class Solver {
|
||||
private:
|
||||
Matrix m_Matrix;
|
||||
|
||||
public:
|
||||
Solver(const Matrix& mat);
|
||||
|
||||
~Solver() {}
|
||||
|
||||
Vect Image() const;
|
||||
Vect Kernel() const;
|
||||
|
||||
VectAffine TriangularSystem() const;
|
||||
|
||||
std::size_t Rank() const;
|
||||
};
|
||||
88
src/Vect.cpp
88
src/Vect.cpp
@@ -2,22 +2,27 @@
|
||||
|
||||
#include "Gauss.h"
|
||||
#include "Solver.h"
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
Vect::Vect(const Matrix& mat) : m_Data(mat) {
|
||||
static bool IsColumnNull(Matrix& mat, std::size_t column) {
|
||||
for (std::size_t i = 0; i < mat.GetRawCount(); i++) {
|
||||
if (!IsEqualZero(mat.at(i, column))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Vect::Vect(Matrix&& a_Matrix) : m_Data(std::move(a_Matrix)) {
|
||||
m_Data.Transpose();
|
||||
Gauss::GaussJordan(m_Data, false, false);
|
||||
m_Data.Transpose();
|
||||
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 (i == mat.GetRawCount()) {
|
||||
if (IsColumnNull(mat, j)) {
|
||||
m_Data = mat.SubMatrix(0, 0, mat.GetRawCount(), j);
|
||||
return;
|
||||
}
|
||||
@@ -25,66 +30,69 @@ void Vect::Simplify() {
|
||||
m_Data = mat;
|
||||
}
|
||||
|
||||
Matrix Vect::GetVector(std::size_t a_Index) const {
|
||||
return m_Data.SubMatrix(0, a_Index, m_Data.GetRawCount(), 1);
|
||||
}
|
||||
|
||||
std::size_t Vect::GetCardinal() const {
|
||||
return m_Data.GetColumnCount();
|
||||
}
|
||||
|
||||
bool Vect::operator==(const Vect& other) const {
|
||||
if (GetDimension() != other.GetDimension() || GetCardinal() != other.GetCardinal())
|
||||
bool Vect::IsElementOf(const Matrix& a_Vector) const {
|
||||
Vect base = *this;
|
||||
base.AddVector(a_Vector);
|
||||
return base.GetCardinal() == GetCardinal();
|
||||
}
|
||||
|
||||
bool Vect::operator==(const Vect& a_Other) const {
|
||||
if (GetDimension() != a_Other.GetDimension() || GetCardinal() != a_Other.GetCardinal())
|
||||
return false;
|
||||
|
||||
// on vérifie si chaque vecteur de la deuxième base appartient à la première base
|
||||
// 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(a_Other.GetVector(i)))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Vect::AddVector(const Matrix& mat) {
|
||||
m_Data.Augment(mat);
|
||||
void Vect::AddVector(const Matrix& a_Vector) {
|
||||
m_Data.Augment(a_Vector);
|
||||
m_Data.Transpose();
|
||||
Gauss::GaussJordan(m_Data, false, false);
|
||||
m_Data.Transpose();
|
||||
Simplify();
|
||||
}
|
||||
|
||||
bool Vect::operator!=(const Vect& other) const {
|
||||
return !(*this == other);
|
||||
bool Vect::operator!=(const Vect& a_Other) const {
|
||||
return !(*this == a_Other);
|
||||
}
|
||||
|
||||
Matrix Vect::GetLinearSystem() const {
|
||||
Matrix vect = m_Data;
|
||||
vect.Transpose();
|
||||
|
||||
Solver solver {vect};
|
||||
vect = solver.Kernel().m_Data;
|
||||
vect.Transpose();
|
||||
return vect;
|
||||
}
|
||||
|
||||
void Vect::Print() const {
|
||||
std::cout << "Espace vectoriel de dimension " << GetCardinal() << " 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++) {
|
||||
std::cout << "[ " << m_Data.at(i, j) << " ]\t";
|
||||
}
|
||||
std::cout << "\n";
|
||||
}
|
||||
Solver solver;
|
||||
Matrix result = solver.Kernel(std::move(vect)).m_Data;
|
||||
result.Transpose();
|
||||
return result;
|
||||
}
|
||||
|
||||
std::size_t Vect::GetDimension() const {
|
||||
return m_Data.GetRawCount();
|
||||
}
|
||||
|
||||
VectAffine::VectAffine(const Vect& base, const Matrix& origine) :
|
||||
m_Base(base), m_Origin(origine.SubMatrix(0, 0, m_Base.GetDimension(), 1)) {}
|
||||
VectAffine::VectAffine(const Vect& a_Base, const Matrix& a_Origin) :
|
||||
m_Base(a_Base), m_Origin(a_Origin.SubMatrix(0, 0, m_Base.GetDimension(), 1)) {}
|
||||
|
||||
void VectAffine::Print() const {
|
||||
std::cout << "\tEspace Affine :\n\n";
|
||||
m_Base.Print();
|
||||
std::cout << "\nOrigine :\n\n";
|
||||
m_Origin.Print();
|
||||
bool VectAffine::IsElementOf(const Matrix& a_Vector) const {
|
||||
return m_Base.IsElementOf(a_Vector - m_Origin);
|
||||
}
|
||||
|
||||
Matrix VectAffine::GetLinearSystem() const {
|
||||
Matrix result = m_Base.GetLinearSystem();
|
||||
|
||||
result.Augment(m_Origin.SubMatrix(0, 0, result.GetRawCount(), 1));
|
||||
|
||||
return result;
|
||||
}
|
||||
58
src/Vect.h
58
src/Vect.h
@@ -1,58 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Matrix.h"
|
||||
|
||||
// espace vectoriel
|
||||
class Vect {
|
||||
private:
|
||||
Matrix m_Data;
|
||||
|
||||
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;
|
||||
|
||||
std::size_t GetDimension() const;
|
||||
std::size_t GetCardinal() const;
|
||||
|
||||
Matrix GetLinearSystem() const;
|
||||
|
||||
/**
|
||||
* \brief Concatène la base actuelle avec un nouveau vecteur
|
||||
* \param mat Une matrice colonne de taille GetDimension()
|
||||
*/
|
||||
void AddVector(const Matrix& mat);
|
||||
|
||||
bool operator==(const Vect& other) const;
|
||||
bool operator!=(const Vect& other) const;
|
||||
|
||||
private:
|
||||
void Simplify();
|
||||
};
|
||||
|
||||
class VectAffine {
|
||||
private:
|
||||
Vect m_Base;
|
||||
Matrix m_Origin;
|
||||
|
||||
public:
|
||||
VectAffine(const Vect& base, const Matrix& origin);
|
||||
|
||||
void Print() const;
|
||||
|
||||
const Vect& GetBase() const {
|
||||
return m_Base;
|
||||
}
|
||||
|
||||
const Matrix& GetOrigin() const {
|
||||
return m_Origin;
|
||||
}
|
||||
};
|
||||
38
src/main.cpp
38
src/main.cpp
@@ -1,4 +1,7 @@
|
||||
#include "Gauss.h"
|
||||
#include "IO.h"
|
||||
#include "Matrix.h"
|
||||
#include "NR.h"
|
||||
#include "Solver.h"
|
||||
#include <iostream>
|
||||
|
||||
@@ -17,45 +20,36 @@ void test() {
|
||||
mat.Print();
|
||||
// mat.Save("matrice4x4echelonne.mat"); */
|
||||
|
||||
Matrix mat2 {"matrice4x4.mat"};
|
||||
mat2.Print();
|
||||
Matrix mat2 = LoadMatrix("matrice4x4.mat");
|
||||
Print(mat2);
|
||||
|
||||
Solver solver {mat2};
|
||||
Solver solver;
|
||||
|
||||
Vect image = solver.Image();
|
||||
Vect noyau = solver.Kernel();
|
||||
Vect image = solver.Image(Matrix{mat2});
|
||||
Vect noyau = solver.Kernel(Matrix{mat2});
|
||||
|
||||
std::cout << "\tImage :\n";
|
||||
image.Print();
|
||||
Print(image);
|
||||
std::cout << "Système :\n";
|
||||
image.GetLinearSystem().Print();
|
||||
Print(image.GetLinearSystem());
|
||||
std::cout << "\tNoyau :\n";
|
||||
noyau.Print();
|
||||
Print(noyau);
|
||||
std::cout << "Système :\n";
|
||||
noyau.GetLinearSystem().Print();
|
||||
Print(noyau.GetLinearSystem());
|
||||
|
||||
std::cout << "\n\n";
|
||||
solver.TriangularSystem().Print();
|
||||
// Print(solver.TriangularSystem(mat2));
|
||||
}
|
||||
|
||||
void prompt() {
|
||||
std::cout << "Quelle est le nombre de lignes de votre matrice ?" << std::endl;
|
||||
std::size_t lignes;
|
||||
std::cin >> lignes;
|
||||
std::cout << "Quelle est le nombre de colonnes de votre matrice ?" << std::endl;
|
||||
std::size_t colonnes;
|
||||
std::cin >> colonnes;
|
||||
std::size_t dimension = lignes * colonnes;
|
||||
std::cout << "Rentrez les coefficients de la matrice" << std::endl;
|
||||
Matrix mat(lignes, colonnes);
|
||||
|
||||
mat.Insert();
|
||||
Matrix mat = InsertMatrix();
|
||||
|
||||
mat.Print();
|
||||
Print(mat);
|
||||
|
||||
Gauss::GaussJordan(mat, true, true);
|
||||
|
||||
mat.Print();
|
||||
Print(mat);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
Reference in New Issue
Block a user