Commit 99b46790 authored by David Rei's avatar David Rei

maj exo1 + sortie

parent f2b7e253
--- ---
title: "A 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
...@@ -26,3 +26,19 @@ theta = pi/2*runif(N) ...@@ -26,3 +26,19 @@ 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²+Y²\le 1 = \pi/4$ (voir [méthode de Monte Carlo sur Wikipédia](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²+Y²$ est inférieur à 1 :
```{r}
4*mean(df$Accept)
```
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