Multiple Runs
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
static Bounds bounds;
|
||||
static final float lowerX = 0;
|
||||
@@ -111,24 +114,33 @@ public class Main {
|
||||
double pointsInside = 0;
|
||||
long startTime = System.nanoTime();
|
||||
double real_value = getRealIntegral(bounds.getX());
|
||||
List<Double> integralList = new ArrayList<>();
|
||||
List<Double> errorList = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i< 20; i++) {
|
||||
|
||||
for (int i = 0; i< threadCount; i++) {
|
||||
Point toTestPoint;
|
||||
for (int ii = 0; ii < samples; ii++) {
|
||||
toTestPoint = bounds.getRandomPoint();
|
||||
if (getIsInside(toTestPoint)) {
|
||||
pointsInside++;
|
||||
}
|
||||
}
|
||||
|
||||
Threading t = new Threading();
|
||||
t.start();t.join();
|
||||
pointsInside += t.getPoints();
|
||||
double integral = (pointsInside/(samples)) * bounds.area();
|
||||
double error = Math.abs(real_value-integral);
|
||||
errorList.add(error); integralList.add(integral);
|
||||
integral = 0; error = 0; pointsInside = 0;
|
||||
|
||||
}
|
||||
|
||||
double integral = (pointsInside/(samples*threadCount)) * bounds.area();
|
||||
double error = Math.abs(real_value-integral);
|
||||
|
||||
System.out.println("The approximated Integral of the function is: " + String.format("%.2f", integral));
|
||||
|
||||
System.out.println("The approximated Integral of the function is: " + String.format("%.2f", integralList.getFirst()));
|
||||
System.out.println("The real Integral of the function is: " + String.format("%.2f",real_value));
|
||||
System.out.println("That's an error of " + String.format("%.8f", error) +" or " + String.format("%.8f",(error/real_value)*100) + "%");
|
||||
System.out.println("And the whole thing took " + String.format("%.6f", (System.nanoTime()-startTime)/1000000000.0) + " Seconds for " + String.format("%,.0f", samples*threadCount) + " samples");
|
||||
|
||||
System.out.println("That's an error of " + String.format("%.8f", errorList.getFirst()) +" or " + String.format("%.8f",(errorList.getFirst()/real_value)*100) + "%");
|
||||
System.out.println("And the whole thing took " + String.format("%.6f", (System.nanoTime()-startTime)/1000000000.0) + " Seconds for " + String.format("%,.0f", samples) + " samples");
|
||||
System.out.println(errorList); System.out.println(integralList);
|
||||
}
|
||||
static class Threading extends Thread {
|
||||
private double pointsInsideThread = 0;
|
||||
|
||||
Reference in New Issue
Block a user