Multiple Runs
This commit is contained in:
29
main.cpp
29
main.cpp
@@ -1,6 +1,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
float lowerX = 0;
|
float lowerX = 0;
|
||||||
float upperX = 20;
|
float upperX = 20;
|
||||||
@@ -113,21 +114,29 @@ int main() {
|
|||||||
auto startTime = std::chrono::high_resolution_clock::now();
|
auto startTime = std::chrono::high_resolution_clock::now();
|
||||||
double pointsInside = 0;
|
double pointsInside = 0;
|
||||||
double samples = 10000000;
|
double samples = 10000000;
|
||||||
|
std::vector<double> listOfErrors;
|
||||||
|
std::vector<double> listOfIntegrals;
|
||||||
Bounds bounds = Bounds(LinearBounds(lowerX, upperX), LinearBounds(getLowerLimit(), getUpperLimit()));
|
Bounds bounds = Bounds(LinearBounds(lowerX, upperX), LinearBounds(getLowerLimit(), getUpperLimit()));
|
||||||
|
double real_value = getRealIntegral(bounds.get_x());
|
||||||
Point toTestPoint;
|
Point toTestPoint;
|
||||||
for (int i = 0; i< samples; i++) {
|
for(int i = 0; i< 20; i++) {
|
||||||
toTestPoint = bounds.getRandomPoint();
|
for (int ii = 0; ii< samples; ii++) {
|
||||||
if (getIsInside(toTestPoint)) {
|
toTestPoint = bounds.getRandomPoint();
|
||||||
pointsInside++;
|
if (getIsInside(toTestPoint)) {
|
||||||
|
pointsInside++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
listOfErrors.push_back(std::abs(real_value-(pointsInside/samples))); listOfIntegrals.push_back(pointsInside/samples);
|
||||||
|
pointsInside = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::cout << std::fixed;
|
std::cout << std::fixed;
|
||||||
std::cout.precision(5);
|
std::cout.precision(5);
|
||||||
double integral = (pointsInside / samples) * bounds.area();
|
double integral = (pointsInside / samples) * bounds.area();
|
||||||
std::cout << "The approximated Integral of the function is: " << integral << "\n";
|
std::cout << "The approximated Integral of the function is: " << integral << "\n";
|
||||||
|
|
||||||
double real_value = getRealIntegral(bounds.get_x());
|
|
||||||
std::cout << "The real Integral of the function is: " << real_value << "\n";
|
std::cout << "The real Integral of the function is: " << real_value << "\n";
|
||||||
|
|
||||||
double error = std::abs(real_value-integral);
|
double error = std::abs(real_value-integral);
|
||||||
@@ -135,7 +144,15 @@ int main() {
|
|||||||
std::chrono::duration<double> duration = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::high_resolution_clock::now()-startTime);
|
std::chrono::duration<double> duration = std::chrono::duration_cast<std::chrono::duration<double>>(std::chrono::high_resolution_clock::now()-startTime);
|
||||||
std::cout << "And the whole thing took " << duration.count() << " Seconds for ";
|
std::cout << "And the whole thing took " << duration.count() << " Seconds for ";
|
||||||
std::cout.precision(0);
|
std::cout.precision(0);
|
||||||
std::cout << samples << " samples";
|
std::cout << samples << " samples" << "\n";
|
||||||
|
|
||||||
|
std::cout.precision(20);
|
||||||
|
for(double m : listOfIntegrals) {
|
||||||
|
std::cout << m << "\n";
|
||||||
|
}
|
||||||
|
for(double m : listOfErrors) {
|
||||||
|
std::cout << m << "\n";
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user