enhanced math.cpp and made while loop for iterative evaluation

This commit is contained in:
emil28092005
2024-09-22 17:51:55 +03:00
parent 3cba9318ef
commit df12b44d35
3 changed files with 95 additions and 19 deletions
+52 -4
View File
@@ -1,7 +1,7 @@
#include "math.h"
#include "matrix.h"
double Math::minVector(ColumnVector columnVector) {
double Math::min(ColumnVector columnVector) {
double temp = columnVector[0];
for (int j = 0; j < columnVector.getColumns(); j++) {
if (columnVector[j] < temp) {
@@ -11,7 +11,7 @@ double Math::minVector(ColumnVector columnVector) {
return temp;
}
double Math::maxVector(ColumnVector columnVector) {
double Math::max(ColumnVector columnVector) {
double temp = columnVector[0];
for (int j = 0; j < columnVector.getColumns(); j++) {
if (columnVector[j] > temp) {
@@ -21,7 +21,31 @@ double Math::maxVector(ColumnVector columnVector) {
return temp;
}
double Math::minArray(std::vector<double> array) {
int Math::min_index(ColumnVector columnVector) {
int temp_index = 0;
double temp = columnVector[0];
for (int j = 0; j < columnVector.getColumns(); j++) {
if (columnVector[j] < temp) {
temp_index = j;
temp = columnVector[j];
}
}
return temp_index;
}
int Math::max_index(ColumnVector columnVector) {
int temp_index = 0;
double temp = columnVector[0];
for (int j = 0; j < columnVector.getColumns(); j++) {
if (columnVector[j] > temp) {
temp_index = j;
temp = columnVector[j];
}
}
return temp_index;
}
double Math::min(std::vector<double> array) {
double temp = array[0];
for (size_t i = 1; i < array.size(); i++) {
if (array[i] < temp) {
@@ -31,7 +55,7 @@ double Math::minArray(std::vector<double> array) {
return temp;
}
double Math::maxArray(std::vector<double> array) {
double Math::max(std::vector<double> array) {
double temp = array[0];
for (size_t i = 1; i < array.size(); i++) {
if (array[i] > temp) {
@@ -40,3 +64,27 @@ double Math::maxArray(std::vector<double> array) {
}
return temp;
}
int Math::min_index(std::vector<double> array) {
int temp_index = 0;
double temp = array[0];
for (size_t i = 1; i < array.size(); i++) {
if (array[i] < temp) {
temp_index = i;
temp = array[i];
}
}
return temp_index;
}
int Math::max_index(std::vector<double> array) {
int temp_index = 0;
double temp = array[0];
for (size_t i = 1; i < array.size(); i++) {
if (array[i] > temp) {
temp_index = i;
temp = array[i];
}
}
return temp_index;
}