# Approximations de pi N <- 100 n <- 1000 V1 <- V2 <- rep(0,N) g <- function(x) sqrt(1-x^2) h <- function(x) (g(x)+g(1-x))/2 x <- seq(0,1,length=200) plot(x, g(x), col="black", type="l", ylab="y") lines(x, h(x), col="blue") for (i in 1:N) { U <- runif(n, min=0, max=1) z1 <- 4*g(U) V1[i] <- mean(z1) # avec les variables antithétiques z2 <- 4*h(U) V2[i] <- mean(z2) } boxplot(list(M_brut=V1, M_antithetique=V2), main=paste("Calcul de pi avec ", n, " simulations", sep=""), sub=paste("Boxplots : résultats pour ", N, " répétitions des ", n, " simulations", sep=""), range=0.001) abline(h=pi, col="red")