elimination added

This commit is contained in:
Spectre
2024-09-22 00:16:38 +07:00
parent c7edcf8232
commit c301992d25
6 changed files with 72 additions and 15 deletions
+27 -2
View File
@@ -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;
}
+31
View File
@@ -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;
}
+13
View File
@@ -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
-1
View File
@@ -1 +0,0 @@
#include "gauss_jordan.h"
-12
View File
@@ -1,12 +0,0 @@
#ifndef GAUSS_JORDAN_H
#define GAUSS_JORDAN_H
class gauss_jordan {
};
#endif //GAUSS_JORDAN_H
+1
View File
@@ -4,6 +4,7 @@
#include <vector>
class ColumnVector;
class Matrix;
class Math {
public: