dev.new(width=7,height=3.5)
par(mfrow=c(1,2), mar=c(3,2,2,1)) # affianco i due grafici in 1 finestra
#
plot(c(-1,1),c(-1,1),type="n",xlab="", ylab="", asp=1)
abline(v=axTicks(1), h=axTicks(2), col="red",lty=3)
symbols(0, 0, circles=1, inches=FALSE, add=TRUE, fg="blue")
n <- 0; ok <- 0
for (i in 1:10000) {x <- runif(1)*2-1; y <- runif(1)*2-1; d <- x*x+y*y
if(d < 1){n <- n+1; points(x,y,type="p", pch="."); if(d < 0.25) ok <- ok+1} }
symbols(0, 0, circles=1/2, inches=FALSE, add=TRUE, fg="blue")
noquote(c("n.lanci","   % OK")); print(c(n, ok/n*100))
#
plot(c(-1,1),c(-1,1),type="n",xlab="", ylab="", asp=1)
abline(v=axTicks(1), h=axTicks(2), col="red",lty=3)
symbols(0, 0, circles=1, inches=FALSE, add=TRUE, fg="blue")
symbols(0, 0, circles=1/2, inches=FALSE, add=TRUE, fg="blue")
pi2 <- atan(1)*8; ok <- 0; n <- 10000
for(i in 1:n) {r <- runif(1); a <- runif(1)*pi2
x <- r*cos(a); y <- r*sin(a); d <- x*x+y*y
points(x,y,type="p", pch="."); if(d < 0.25) ok <- ok+1}
noquote(c("n.lanci","   % OK")); print(c(n, ok/n*100))
# fine tracciamento