Elimination func created
This commit is contained in:
@@ -2,15 +2,45 @@
|
||||
#include "tools/matrix.h"
|
||||
#include "tools/math.h"
|
||||
|
||||
struct DestroyMatrix {
|
||||
Matrix A;
|
||||
ColumnVector C;
|
||||
ColumnVector b;
|
||||
};
|
||||
|
||||
DestroyMatrix destroyGeneralMatrix(Matrix& generalMatrix) {
|
||||
int rows = generalMatrix.getRows();
|
||||
int cols = generalMatrix.getColumns();
|
||||
|
||||
Matrix A(rows - 1, cols - 1);
|
||||
ColumnVector C(cols - 1);
|
||||
ColumnVector b(rows - 1);
|
||||
|
||||
for (int j = 0; j < cols - 1; ++j) {
|
||||
C[j] = generalMatrix[0][j];
|
||||
}
|
||||
|
||||
for (int i = 1; i < rows; ++i) {
|
||||
b[i - 1] = generalMatrix[i - 1][cols - 1];
|
||||
}
|
||||
|
||||
for (int i = 1; i < rows; ++i) {
|
||||
for (int j = 0; j < cols - 1; ++j) {
|
||||
A[i - 1][j] = generalMatrix[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
return {A, C, b};
|
||||
}
|
||||
|
||||
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];
|
||||
generalMatrix[j][A.getColumns()] = b[j];
|
||||
}
|
||||
|
||||
for (int i = 0; i < A.getRows(); i++) {
|
||||
@@ -28,13 +58,13 @@ int main() {
|
||||
std::cin >> m;
|
||||
|
||||
ColumnVector C(n);
|
||||
Matrix A(n, m);
|
||||
ColumnVector b(n);
|
||||
Matrix A(m - 1, n);
|
||||
ColumnVector b(m);
|
||||
double eps;
|
||||
double eps_default;
|
||||
std::cin >> C;
|
||||
std::cin >> A;
|
||||
std::cin >> b;
|
||||
std::cin >> A;
|
||||
|
||||
std::cout << "Вектор C: " << C << std::endl;
|
||||
std::cout << "Вектор b: " << b << std::endl;
|
||||
@@ -42,8 +72,14 @@ int main() {
|
||||
std::cout << "Матрица A: " << A << std::endl;
|
||||
|
||||
Matrix E = createGeneralMatrix(A, C, b);
|
||||
std::cout << "Матрица E: " << E << std::endl;
|
||||
|
||||
DestroyMatrix destroyed = destroyGeneralMatrix(E);
|
||||
std::cout << "Вектор C: " << destroyed.C << std::endl;
|
||||
std::cout << "Вектор b: " << destroyed.b << std::endl;
|
||||
|
||||
std::cout << "Матрица A: " << destroyed.A << std::endl;
|
||||
|
||||
std::cout << "Новая матрица:" << E << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user