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 (
runif
returns a vector.
if
takes a single value (not a vector).
Check the manual for runif
, I don't think you are using it right.
In R, it often makes sense to remove for loops and use vectors instead - for example:
bnc1<-function(maxITR=100000, d=2, l=1){
x=runif(maxITR,0,pi);
y=runif(maxITR,0,d/2);
counts = sum((l/2*sin(x)) >= y);
counts/maxITR*d/l
}