diff --git a/main.cpp b/main.cpp index f15b187..fb7dcc8 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include 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 listOfErrors; + std::vector 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++) { - toTestPoint = bounds.getRandomPoint(); - if (getIsInside(toTestPoint)) { - pointsInside++; + 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 duration = std::chrono::duration_cast>(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; }