1
My R Code:Warnung "die Bedingung hat Länge> 1 und nur das erste Element wird verwendet"
bnc1<-function(maxITR=100000, d=2, l=1){
counts=0;
for (i in 1:maxITR){
x=runif(1,0,pi);
y=runif(2,0,d/2);
if ((l/2*sin(x)) >= y) counts=counts+1;
}
counts/maxITR*d/l
}
Ausführen des Code:
> bnc1(maxITR=1000)
[1] 0.652
There were 50 or more warnings (use warnings() to see the first 50)
> warnings()
Warning messages:
1: In if ((l/2 * sin(x)) >= y) counts = counts + 1 ... :
the condition has length > 1 and only the first element will be used
2: In if ((l/2 * sin(x)) >= y) counts = counts + 1 ... :
the condition has length > 1 and only the first element will be used
...
49: In if ((l/2 * sin(x)) >= y) counts = counts + 1 ... :
the condition has length > 1 and only the first element will be used
50: In if ((l/2 * sin(x)) >= y) counts = counts + 1 ... :
the condition has length > 1 and only the first element will be used
Hat jemand eine Idee hat, was die Ursachen Warnungen?
Dank! y = runif (2,0, d/2) sollte y = runif (1,0, d/2) sein. – Tim
Okay, hört sich an, als hättest du eine Lösung. Vielleicht finden Sie mein Beispiel ist eine sinnvolle Vereinfachung. –
Danke! Ihr Code ist viel effizienter! – Tim