From 7d8ca209198c9eff8b6bac36965bd084aa500cff Mon Sep 17 00:00:00 2001 From: b05f84b9ee021dccccc4787bb5a09153 Date: Mon, 15 Mar 2021 15:24:34 +0000 Subject: [PATCH] Update2 toy_document_fr.Rmd --- module2/exo1/toy_document_fr.Rmd | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/module2/exo1/toy_document_fr.Rmd b/module2/exo1/toy_document_fr.Rmd index e0cfd0a..b9595cc 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() ``` -- 2.18.1