From 2a4b3a7e82f6e3df3f2ae5af5c8597d82168dac1 Mon Sep 17 00:00:00 2001 From: b05f84b9ee021dccccc4787bb5a09153 Date: Mon, 15 Mar 2021 15:07:30 +0000 Subject: [PATCH] Update toy_document_fr.Rmd --- module2/exo1/toy_document_fr.Rmd | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/module2/exo1/toy_document_fr.Rmd b/module2/exo1/toy_document_fr.Rmd index 744e706..e0cfd0a 100644 --- a/module2/exo1/toy_document_fr.Rmd +++ b/module2/exo1/toy_document_fr.Rmd @@ -1,33 +1,36 @@ --- -title: "À propos du calcul de Pi" -author: "ljl" -date: "8 mars 2021" +title: "À propos du calcul de pi" +author: "Arnaud Legrand" +date: "25 juin 2018" output: html_document --- -```{r setup, include=FALSE} -knitr::opts_chunk$set(echo = TRUE) -``` - ## En demandant à la lib maths + Mon ordinateur m'indique que $\pi$ vaut *approximativement* -```{r cars} + +```{r} pi ``` - ## En utilisant la méthode des aiguilles de Buffon Mais calculé avec la **méthode** des [aiguilles de Buffon](https://fr.wikipedia.org/wiki/Aiguille_de_Buffon), on obtiendrait comme **approximation** : -```{r } +```{r} set.seed(42) + N = 100000 + x = runif(N) + theta = pi/2*runif(N) + 2/(mean(x+sin(theta)>1)) ``` + ## Avec un argument “fréquentiel” de surface + Sinon, une méthode plus simple à comprendre et ne faisant pas intervenir d’appel à la fonction sinus se base sur le fait que si $X \sim U(0,1)$ et $Y \sim U(0,1)$ alors @@ -36,10 +39,15 @@ $P[X^{2} + Y^{2} \leq 1]= \pi /4$ ```{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) + ggplot(df, aes(x=X,y=Y,color=Accept)) + geom_point(alpha=.2) + coord_fixed() + theme_bw() ``` -- 2.18.1