From 042ce5d1410aad06489de3a8cd738d893aff8a35 Mon Sep 17 00:00:00 2001 From: Parric007 Date: Thu, 16 May 2024 11:56:38 +0200 Subject: [PATCH] Multiple Runs --- src/Main.kt | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Main.kt b/src/Main.kt index bf516b8..d3ff95d 100644 --- a/src/Main.kt +++ b/src/Main.kt @@ -96,18 +96,20 @@ fun main() { val format = DecimalFormat("#,###.##") var pointsInside = 0.0 - val samples = 20_000_000 + val samples = 10_000_000 val bounds = Bounds(LinearBounds(lowerX.toFloat(), upperX.toFloat()), LinearBounds(getLowerLimit(), getUpperLimit())) var integral = 0.0 - var error = 0.0 - var result = 0.0 + //var error = 0.0 + //var result = 0.0 + val listOfIntegrals = mutableListOf(); + val listOfErrors = mutableListOf(); val realValue = getRealIntegral(bounds.getX()) var toTestPoint : Point val elapsed = measureTimeMillis { - for(i in 0..50){ + for(i in 0..20){ for(ii in 0..samples) { toTestPoint = bounds.getRandomPoint() if(getIsInside(toTestPoint)){ @@ -117,15 +119,17 @@ fun main() { integral = (pointsInside/samples) * bounds.area() - result += integral + listOfErrors.add(abs(realValue-integral)) + listOfIntegrals.add(integral) integral = 0.0 pointsInside = 0.0 } - result /= 50.0 - error = abs(realValue-result) + //result /= 50.0 + //error = abs(realValue-result) } - println("The approximated Integral of the function is: " + format.format(result)) + println("The approximated Integral of the function is: " + format.format(listOfIntegrals.first())) println("The real Integral of the function is: " + format.format(realValue)) - println("That's an error of " + format.format(error) + " or " + format.format((error/realValue)*100) + "%") - println("And the whole thing took " + format.format(elapsed/1000.0) + " Seconds for 50 times" + format.format(samples) + " Samples") + println("That's an error of " + format.format(listOfErrors.first()) + " or " + format.format((listOfErrors.first()/realValue)*100) + "%") + println("And the whole thing took " + format.format(elapsed/1000.0) + " Seconds for 20 times " + format.format(samples) + " Samples") + println(listOfErrors); println(listOfIntegrals) } \ No newline at end of file