From c301992d25a25ef3353dc780342c2617521c1e3c Mon Sep 17 00:00:00 2001 From: Spectre Date: Sun, 22 Sep 2024 00:16:38 +0700 Subject: [PATCH] elimination added --- main.cpp | 29 +++++++++++++++++++++++++++-- tools/elimination.cpp | 31 +++++++++++++++++++++++++++++++ tools/elimination.h | 13 +++++++++++++ tools/gauss_jordan.cpp | 1 - tools/gauss_jordan.h | 12 ------------ tools/math.h | 1 + 6 files changed, 72 insertions(+), 15 deletions(-) create mode 100644 tools/elimination.cpp create mode 100644 tools/elimination.h delete mode 100644 tools/gauss_jordan.cpp delete mode 100644 tools/gauss_jordan.h diff --git a/main.cpp b/main.cpp index df1ab18..7c89b5e 100644 --- a/main.cpp +++ b/main.cpp @@ -2,6 +2,26 @@ #include "tools/matrix.h" #include "tools/math.h" +Matrix createGeneralMatrix(Matrix& A, ColumnVector& C, ColumnVector& b) { + Matrix generalMatrix(A.getRows() + 1, A.getColumns() + 1); + for (int i = 0; i < A.getColumns(); i++) { + generalMatrix[0][i] = C[i]; + } + + generalMatrix[0][A.getColumns()] = 0; + for (int j = 0; j < A.getRows(); j++) { + generalMatrix[j + 1][A.getColumns()] = b[j]; + } + + for (int i = 0; i < A.getRows(); i++) { + for (int j = 0; j < A.getColumns(); j++) { + generalMatrix[i + 1][j] = A[i][j]; + } + } + + return generalMatrix; +} + int main() { int n, m; std::cin >> n; @@ -12,13 +32,18 @@ int main() { ColumnVector b(n); double eps; double eps_default; + std::cin >> C; std::cin >> A; + std::cin >> b; std::cout << "Вектор C: " << C << std::endl; + std::cout << "Вектор b: " << b << std::endl; std::cout << "Матрица A: " << A << std::endl; - Matrix B(2, 2); - std::cout << B << std::endl; + Matrix E = createGeneralMatrix(A, C, b); + + std::cout << "Новая матрица:" << E << std::endl; + return 0; } diff --git a/tools/elimination.cpp b/tools/elimination.cpp new file mode 100644 index 0000000..8182f67 --- /dev/null +++ b/tools/elimination.cpp @@ -0,0 +1,31 @@ +#include "elimination.h" +#include "matrix.h" +#include "math.h" + +Matrix createGeneralMatrix(Matrix& A, ColumnVector& C, ColumnVector& b) { + Matrix generalMatrix(A.getRows() + 1, A.getColumns() + 1); + for (int i = 0; i < A.getColumns(); i++) { + generalMatrix[0][i] = C[i]; + } + + generalMatrix[0][A.getColumns()] = 0; + for (int j = 0; j < A.getRows(); j++) { + generalMatrix[j + 1][A.getColumns()] = b[j]; + } + + for (int i = 0; i < A.getRows(); i++) { + for (int j = 0; j < A.getColumns(); j++) { + generalMatrix[i + 1][j] = A[i][j]; + } + } + + return generalMatrix; +} + +Matrix elimination(Matrix A, ColumnVector C, ColumnVector b, int pivot_column_index, int pivot_row_index, double eps) { + Matrix generalMatrix = createGeneralMatrix(A, C, b); + + + return generalMatrix; +} + diff --git a/tools/elimination.h b/tools/elimination.h new file mode 100644 index 0000000..a57e6d3 --- /dev/null +++ b/tools/elimination.h @@ -0,0 +1,13 @@ +#ifndef ELIMINATION_H +#define ELIMINATION_H + + + +class Elimination { + public: + Matrix elimination(Matrix A, ColumnVector C, ColumnVector b, int pivot_column_index, int pivot_row_index, double eps); +}; + + + +#endif //ELIMINATION_H diff --git a/tools/gauss_jordan.cpp b/tools/gauss_jordan.cpp deleted file mode 100644 index de26809..0000000 --- a/tools/gauss_jordan.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "gauss_jordan.h" diff --git a/tools/gauss_jordan.h b/tools/gauss_jordan.h deleted file mode 100644 index 0666382..0000000 --- a/tools/gauss_jordan.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef GAUSS_JORDAN_H -#define GAUSS_JORDAN_H - - - -class gauss_jordan { - -}; - - - -#endif //GAUSS_JORDAN_H diff --git a/tools/math.h b/tools/math.h index b641471..8ff38f0 100644 --- a/tools/math.h +++ b/tools/math.h @@ -4,6 +4,7 @@ #include class ColumnVector; +class Matrix; class Math { public: