no commit message

parent 8ef286d7
...@@ -5,7 +5,41 @@ ...@@ -5,7 +5,41 @@
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [] "source": [
"---\n",
"title: \"À propos du calcul de pi\"\n",
"author: \"Arnaud Legrand\"\n",
"date: \"25 juin 2018\"\n",
"output: html_document\n",
"---\n",
"\n",
"```{r setup, include=FALSE}\n",
"knitr::opts_chunk$set(echo = TRUE)\n",
"En demandant à la lib maths\n",
"Mon ordinateur m'indique que ( \\pi ) vaut approximativement :\n",
"pi\n",
"En utilisant la méthode des aiguilles de Buffon\n",
"Mais calculé avec la méthode des aiguilles de Buffon, on obtiendrait comme approximation :\n",
"set.seed(42)\n",
"N <- 100000\n",
"x <- runif(N)\n",
"theta <- pi/2 * runif(N)\n",
"2 / (mean(x + sin(theta) > 1))\n",
"Avec un argument « fréquentiel » de surface\n",
"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 ( \\mathbb{P}[X^2 + Y^2 \\le 1] = \\pi/4 ). Le code suivant illustre ce fait :\n",
"set.seed(42)\n",
"N <- 1000\n",
"df <- data.frame(X = runif(N), Y = runif(N))\n",
"df $ Accept <- (df $ X^2 + df$Y^2 <= 1)\n",
"\n",
"library(ggplot2)\n",
"ggplot(df, aes(x = X, y = Y, color = Accept)) +\n",
" geom_point(alpha = .2) +\n",
" coord_fixed() +\n",
" theme_bw()\n",
"Il est alors aisé d'obtenir une approximation (pas terrible) de ( \\pi ) en comptant combien de fois, en moyenne, ( X^2 + Y^2 ) est inférieur à 1 :\n",
"4 * mean(df$Accept)"
]
} }
], ],
"metadata": { "metadata": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment