From c64341836b65fd13ef3d45cca16fd01b7a61f2e4 Mon Sep 17 00:00:00 2001 From: mamane Date: Thu, 14 May 2020 20:30:42 +0100 Subject: [PATCH] resulexo2 --- module2/exo1/toy_document_fr.html | 449 ++++++++++++++++++++++++++++++ mooc-rr.Rproj | 13 + 2 files changed, 462 insertions(+) create mode 100644 module2/exo1/toy_document_fr.html create mode 100644 mooc-rr.Rproj diff --git a/module2/exo1/toy_document_fr.html b/module2/exo1/toy_document_fr.html new file mode 100644 index 0000000..8dfb770 --- /dev/null +++ b/module2/exo1/toy_document_fr.html @@ -0,0 +1,449 @@ + + + + + + + + + + + + + + + +A propos du calcul de Pi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
+

En demandant à R

+

Mon ordinateur m’indique que π vaut approximativement

+
pi
+
## [1] 3.141593
+
+
+

En utilisant la méthode des aiguille de Buffon

+

a Mais calculé avec la méthode des Aiguille_de_Buffona , on obtiendrait comme approximation :

+
set.seed(42)
+N = 100000
+x = runif(N)
+theta = pi/2*runif(N)
+2/(mean(x+sin(theta)>1))
+
## [1] 3.14327
+
+
+

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∼U(0,1) et Y∼U(0,1) alors P[X2+Y2≤1]=π/4 voir méthode de Monte Carlo sur Wikipedia. Le code suivant illustre ce fait

+
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()
+

+

Il est alors aisé d’obtenir une approximation (pas terrible) de π en comptant combien de fois, en moyenne,X2 + Y2 est inférieur à 1:

+
4*mean(df$Accept)
+
## [1] 3.156
+
+ + + + +
+ + + + + + + + + + + + + + + diff --git a/mooc-rr.Rproj b/mooc-rr.Rproj new file mode 100644 index 0000000..8e3c2eb --- /dev/null +++ b/mooc-rr.Rproj @@ -0,0 +1,13 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX -- 2.18.1