My R code:
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
}
Running the 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
Does anyone has an idea what causes the warnings?