Multiple Runs
This commit is contained in:
18
.idea/workspace.xml
generated
18
.idea/workspace.xml
generated
@@ -19,15 +19,16 @@
|
|||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent">{
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"kotlin-language-version-configured": "true",
|
"git-widget-placeholder": "main",
|
||||||
"nodejs_package_manager_path": "npm",
|
"kotlin-language-version-configured": "true",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"nodejs_package_manager_path": "npm",
|
||||||
|
"vue.rearranger.settings.migration": "true"
|
||||||
}
|
}
|
||||||
}</component>
|
}]]></component>
|
||||||
<component name="SharedIndexes">
|
<component name="SharedIndexes">
|
||||||
<attachedChunks>
|
<attachedChunks>
|
||||||
<set>
|
<set>
|
||||||
@@ -45,6 +46,7 @@
|
|||||||
<updated>1713175398866</updated>
|
<updated>1713175398866</updated>
|
||||||
<workItem from="1713175399721" duration="45000" />
|
<workItem from="1713175399721" duration="45000" />
|
||||||
<workItem from="1714631445701" duration="14000" />
|
<workItem from="1714631445701" duration="14000" />
|
||||||
|
<workItem from="1715852446738" duration="21000" />
|
||||||
</task>
|
</task>
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
static Bounds bounds;
|
static Bounds bounds;
|
||||||
static final float lowerX = 0;
|
static final float lowerX = 0;
|
||||||
@@ -111,24 +114,33 @@ public class Main {
|
|||||||
double pointsInside = 0;
|
double pointsInside = 0;
|
||||||
long startTime = System.nanoTime();
|
long startTime = System.nanoTime();
|
||||||
double real_value = getRealIntegral(bounds.getX());
|
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();
|
double integral = (pointsInside/(samples)) * bounds.area();
|
||||||
t.start();t.join();
|
double error = Math.abs(real_value-integral);
|
||||||
pointsInside += t.getPoints();
|
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("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("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*threadCount) + " samples");
|
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 {
|
static class Threading extends Thread {
|
||||||
private double pointsInsideThread = 0;
|
private double pointsInsideThread = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user