Hallo!
Ich bräuchte Hilfe bei folgender Aufgabe:
1. Wie lässt sich mathematisch begründen, dass output sich in diesem Algorithmus an Pi annähert? Wie heißt der Algorithmus und wofür wird er verwendet?
public class Test {
2. Wir wollen die Abbruchbedingung in der for-Schleife nun verändern und nicht eine bestimmte Anzahl an Iterationen betrachten, sondern das Ergebnis auf eine bestimmte Genauigkeit (0.000001) annähern. Wie sieht der neue Quellcode aus?
Ich bräuchte Hilfe bei folgender Aufgabe:
1. Wie lässt sich mathematisch begründen, dass output sich in diesem Algorithmus an Pi annähert? Wie heißt der Algorithmus und wofür wird er verwendet?
public class Test {
public static void main(String[] args){
}int g = 10000;
int v = 0;
double x,y;
double output;
for (int i = 1; i<= g; i++) {
x = Math.random();
y = Math.random();
if (Math.hypot(x,y) <= 1)
output = 4*(double)v / g;
System.out.printf("Output: %g%n", output);
System.out.println(v);
}int v = 0;
double x,y;
double output;
for (int i = 1; i<= g; i++) {
x = Math.random();
y = Math.random();
if (Math.hypot(x,y) <= 1)
v++;
}output = 4*(double)v / g;
System.out.printf("Output: %g%n", output);
System.out.println(v);
2. Wir wollen die Abbruchbedingung in der for-Schleife nun verändern und nicht eine bestimmte Anzahl an Iterationen betrachten, sondern das Ergebnis auf eine bestimmte Genauigkeit (0.000001) annähern. Wie sieht der neue Quellcode aus?