Multiple Runs
This commit is contained in:
24
src/Main.kt
24
src/Main.kt
@@ -96,18 +96,20 @@ fun main() {
|
|||||||
|
|
||||||
val format = DecimalFormat("#,###.##")
|
val format = DecimalFormat("#,###.##")
|
||||||
var pointsInside = 0.0
|
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()))
|
val bounds = Bounds(LinearBounds(lowerX.toFloat(), upperX.toFloat()), LinearBounds(getLowerLimit(), getUpperLimit()))
|
||||||
|
|
||||||
var integral = 0.0
|
var integral = 0.0
|
||||||
var error = 0.0
|
//var error = 0.0
|
||||||
var result = 0.0
|
//var result = 0.0
|
||||||
|
val listOfIntegrals = mutableListOf<Double>();
|
||||||
|
val listOfErrors = mutableListOf<Double>();
|
||||||
|
|
||||||
val realValue = getRealIntegral(bounds.getX())
|
val realValue = getRealIntegral(bounds.getX())
|
||||||
var toTestPoint : Point
|
var toTestPoint : Point
|
||||||
|
|
||||||
val elapsed = measureTimeMillis {
|
val elapsed = measureTimeMillis {
|
||||||
for(i in 0..50){
|
for(i in 0..20){
|
||||||
for(ii in 0..samples) {
|
for(ii in 0..samples) {
|
||||||
toTestPoint = bounds.getRandomPoint()
|
toTestPoint = bounds.getRandomPoint()
|
||||||
if(getIsInside(toTestPoint)){
|
if(getIsInside(toTestPoint)){
|
||||||
@@ -117,15 +119,17 @@ fun main() {
|
|||||||
|
|
||||||
|
|
||||||
integral = (pointsInside/samples) * bounds.area()
|
integral = (pointsInside/samples) * bounds.area()
|
||||||
result += integral
|
listOfErrors.add(abs(realValue-integral))
|
||||||
|
listOfIntegrals.add(integral)
|
||||||
integral = 0.0
|
integral = 0.0
|
||||||
pointsInside = 0.0
|
pointsInside = 0.0
|
||||||
}
|
}
|
||||||
result /= 50.0
|
//result /= 50.0
|
||||||
error = abs(realValue-result)
|
//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("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("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 50 times" + format.format(samples) + " Samples")
|
println("And the whole thing took " + format.format(elapsed/1000.0) + " Seconds for 20 times " + format.format(samples) + " Samples")
|
||||||
|
println(listOfErrors); println(listOfIntegrals)
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user