Multiple Runs

This commit is contained in:
Parric007
2024-05-16 11:47:54 +02:00
parent f16c0880bc
commit 560008f06b
2 changed files with 32 additions and 18 deletions

18
.idea/workspace.xml generated
View File

@@ -19,15 +19,16 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;kotlin-language-version-configured&quot;: &quot;true&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"git-widget-placeholder": "main",
"kotlin-language-version-configured": "true",
"nodejs_package_manager_path": "npm",
"vue.rearranger.settings.migration": "true"
}
}</component>
}]]></component>
<component name="SharedIndexes">
<attachedChunks>
<set>
@@ -45,6 +46,7 @@
<updated>1713175398866</updated>
<workItem from="1713175399721" duration="45000" />
<workItem from="1714631445701" duration="14000" />
<workItem from="1715852446738" duration="21000" />
</task>
<servers />
</component>

View File

@@ -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;