1
Mon code R:Attention "la condition a une longueur> 1 et seul le premier élément sera utilisé"
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
}
Exécution du 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
Est-ce que quelqu'un a une idée ce qui cause la avertissements?
Merci! y = runif (2,0, d/2) devrait être y = runif (1,0, d/2). – Tim
ok, on dirait que vous avez une solution. Vous trouverez peut-être que mon exemple est une simplification utile. –
Merci! Votre code est beaucoup plus efficace! – Tim