Multiple Runs
This commit is contained in:
23
main.cpp
23
main.cpp
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <random>
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
|
||||
float lowerX = 0;
|
||||
float upperX = 20;
|
||||
@@ -113,21 +114,29 @@ int main() {
|
||||
auto startTime = std::chrono::high_resolution_clock::now();
|
||||
double pointsInside = 0;
|
||||
double samples = 10000000;
|
||||
std::vector<double> listOfErrors;
|
||||
std::vector<double> listOfIntegrals;
|
||||
Bounds bounds = Bounds(LinearBounds(lowerX, upperX), LinearBounds(getLowerLimit(), getUpperLimit()));
|
||||
double real_value = getRealIntegral(bounds.get_x());
|
||||
Point toTestPoint;
|
||||
for (int i = 0; i< samples; i++) {
|
||||
for(int i = 0; i< 20; i++) {
|
||||
for (int ii = 0; ii< samples; ii++) {
|
||||
toTestPoint = bounds.getRandomPoint();
|
||||
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.precision(5);
|
||||
double integral = (pointsInside / samples) * bounds.area();
|
||||
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";
|
||||
|
||||
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::cout << "And the whole thing took " << duration.count() << " Seconds for ";
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user