diff --git a/module2/exo1/toy_document_fr.Rmd b/module2/exo1/toy_document_fr.Rmd index e0cfd0a5ae782ca31b3678bafc157605fde9c396..b9595cc9b71493dcd95e5f7d495cceee05f0b1fe 100644 --- a/module2/exo1/toy_document_fr.Rmd +++ b/module2/exo1/toy_document_fr.Rmd @@ -18,14 +18,10 @@ pi Mais calculé avec la **méthode** des [aiguilles de Buffon](https://fr.wikipedia.org/wiki/Aiguille_de_Buffon), on obtiendrait comme **approximation** : ```{r} -set.seed(42) - -N = 100000 - -x = runif(N) - -theta = pi/2*runif(N) - +set.seed(42) +N = 100000 +x = runif(N) +theta = pi/2*runif(N) 2/(mean(x+sin(theta)>1)) ``` @@ -38,16 +34,11 @@ $P[X^{2} + Y^{2} \leq 1]= \pi /4$ (voir [méthode de Monte Carlo sur Wikipedia](https://fr.wikipedia.org/wiki/M%C3%A9thode_de_Monte-Carlo#D%C3%A9termination_de_la_valeur_de_%CF%80). Le code suivant illustre ce fait: ```{r } -set.seed(42) - -N = 1000 - -df = data.frame(X = runif(N), Y = runif(N)) - -df$Accept = (df$X**2 + df$Y**2 <=1) - -library(ggplot2) - +set.seed(42) +N = 1000 +df = data.frame(X = runif(N), Y = runif(N)) +df$Accept = (df$X**2 + df$Y**2 <=1) +library(ggplot2) ggplot(df, aes(x=X,y=Y,color=Accept)) + geom_point(alpha=.2) + coord_fixed() + theme_bw() ```