Commit c7253280 authored by pdaude's avatar pdaude

Updata toy_document.Rmd and create html file

parent 4b8f77a7
--- ---
title: "À propos du calcul de pi" title: "À propos du calcul de pi"
author: "Arnaud Legrand" author: "*Arnaud Legrand*"
date: "25 juin 2018" date: "*25 juin 2018*"
output: html_document output: html_document
--- ---
...@@ -12,7 +12,7 @@ knitr::opts_chunk$set(echo = TRUE) ...@@ -12,7 +12,7 @@ knitr::opts_chunk$set(echo = TRUE)
## En demandant à la lib maths ## En demandant à la lib maths
Mon ordinateur m’indique que $\pi$ vaut approximativement. Mon ordinateur m’indique que $\pi$ vaut *approximativement*.
```{r } ```{r }
pi pi
...@@ -30,3 +30,21 @@ theta = pi/2*runif(N) ...@@ -30,3 +30,21 @@ theta = pi/2*runif(N)
2/(mean(x+sin(theta)>1)) 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$\ P[X^2+Y^2≤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)
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 $\pi$ en comptant combien de fois, en moyenne,$\ X^2+Y^2$ est inférieur à 1:
```{r }
4*mean(df$Accept)
```
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
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