math.cpp added
This commit is contained in:
@@ -1,18 +1,24 @@
|
||||
#include <iostream>
|
||||
#include "tools/matrix.h"
|
||||
|
||||
#include "tools/math.h"
|
||||
|
||||
int main() {
|
||||
int n, m;
|
||||
std::cin >> n;
|
||||
std::cin >> m;
|
||||
|
||||
ColumnVector C(n);
|
||||
Matrix A(n, m);
|
||||
ColumnVector b(n);
|
||||
double eps;
|
||||
double eps_default;
|
||||
|
||||
std::cin >> C;
|
||||
std::cin >> A;
|
||||
std::cin >> b;
|
||||
std::cin >> eps;
|
||||
|
||||
std::cout << "Вектор C: " << C << std::endl;
|
||||
|
||||
std::cout << "Матрица A: " << A << std::endl;
|
||||
|
||||
Matrix B(2, 2);
|
||||
std::cout << B << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1 +1,42 @@
|
||||
#include "math.h"
|
||||
#include "matrix.h"
|
||||
|
||||
double Math::minVector(ColumnVector columnVector) {
|
||||
double temp = columnVector[0];
|
||||
for (int j = 0; j < columnVector.getColumns(); j++) {
|
||||
if (columnVector[j] < temp) {
|
||||
temp = columnVector[j];
|
||||
}
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
double Math::maxVector(ColumnVector columnVector) {
|
||||
double temp = columnVector[0];
|
||||
for (int j = 0; j < columnVector.getColumns(); j++) {
|
||||
if (columnVector[j] > temp) {
|
||||
temp = columnVector[j];
|
||||
}
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
double Math::minArray(std::vector<double> array) {
|
||||
double temp = array[0];
|
||||
for (size_t i = 1; i < array.size(); i++) {
|
||||
if (array[i] < temp) {
|
||||
temp = array[i];
|
||||
}
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
double Math::maxArray(std::vector<double> array) {
|
||||
double temp = array[0];
|
||||
for (size_t i = 1; i < array.size(); i++) {
|
||||
if (array[i] > temp) {
|
||||
temp = array[i];
|
||||
}
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
+8
-4
@@ -1,12 +1,16 @@
|
||||
#ifndef MATH_H
|
||||
#define MATH_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
class ColumnVector;
|
||||
|
||||
class math {
|
||||
|
||||
class Math {
|
||||
public:
|
||||
double minVector(ColumnVector columnVector);
|
||||
double maxVector(ColumnVector columnVector);
|
||||
double minArray(std::vector<double> array);
|
||||
double maxArray(std::vector<double> array);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // MATH_H
|
||||
+1
-1
@@ -77,7 +77,7 @@ std::ostream& operator<<(std::ostream& cout, ColumnVector& vectorObj) {
|
||||
Matrix::Matrix(int n, int m) {
|
||||
rows = n;
|
||||
columns = m;
|
||||
matrix.resize(n);
|
||||
matrix.resize(n, ColumnVector(m));
|
||||
for (auto& row : matrix) {
|
||||
row = ColumnVector(m);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user