diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 6570037..e0eb1d6 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -19,15 +19,16 @@
- {
- "keyToString": {
- "RunOnceActivity.OpenProjectViewOnStart": "true",
- "RunOnceActivity.ShowReadmeOnStart": "true",
- "kotlin-language-version-configured": "true",
- "nodejs_package_manager_path": "npm",
- "vue.rearranger.settings.migration": "true"
+
+}]]>
@@ -45,6 +46,7 @@
1713175398866
+
diff --git a/MonteCarlo_Java/src/Main.java b/MonteCarlo_Java/src/Main.java
index 19b0a9b..b05f4bd 100644
--- a/MonteCarlo_Java/src/Main.java
+++ b/MonteCarlo_Java/src/Main.java
@@ -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 integralList = new ArrayList<>();
+ List 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;