Multiple Runs

This commit is contained in:
Parric007
2024-05-16 11:56:38 +02:00
parent b5ed399b0c
commit 042ce5d141

View File

@@ -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<Double>();
val listOfErrors = mutableListOf<Double>();
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)
}