From 347236a2fb9d9426b2c974d643f1763c921e556c Mon Sep 17 00:00:00 2001 From: 40b967d450cc73a5ec8d086a42cb7ff3 Date: Tue, 2 Nov 2021 16:14:53 +0100 Subject: [PATCH] toy_document_orgmode_R_fr.org: Update --- module2/exo1/toy_document_orgmode_R_fr.org | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/module2/exo1/toy_document_orgmode_R_fr.org b/module2/exo1/toy_document_orgmode_R_fr.org index 9a81598..75845eb 100644 --- a/module2/exo1/toy_document_orgmode_R_fr.org +++ b/module2/exo1/toy_document_orgmode_R_fr.org @@ -1,4 +1,4 @@ -#+TITLE: À propos du calcul de $\pi$ +#+TITLE: À propos du calcul de $\pi$ #+LANGUAGE: fr # #+PROPERTY: header-args :eval never-export @@ -21,7 +21,8 @@ pi * En utilisant la méthode des aiguilles de Buffon -Mais calculé avec la *méthode* des [[https://fr.wikipedia.org/wiki/Aiguille_de_Buffon][aiguilles de Buffon]], on obtiendrait comme *approximation* : +Mais calculé avec la *méthode* des [[https://fr.wikipedia.org/wiki/Aiguille_de_Buffon][aiguilles de Buffon]], on obtiendrait +comme *approximation* : #+begin_src R :results output :session *R* :exports both set.seed(42) @@ -31,18 +32,17 @@ theta = pi/2*runif(N) 2/(mean(x+sin(theta)>1)) #+end_src -#+RESULTS: -: +#+RESULTS: : [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 \sim U(0,1)$ et $Y \sim U(0,1)$ alors $P[X² + Y² \le 1] = \pi/4$ (voir -[[https://fr.wikipedia.org/wiki/M%C3%A9thode_de_Monte-Carlo#D%C3%A9termination_de_la_valeur_de_%CF%80][méthode de Monte Carlo sur Wikipédia]]). Le -code suivant illustre ce fait : +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 [[https://fr.wikipedia.org/wiki/M%C3%A9thode_de_Monte-Carlo#D%C3%A9termination_de_la_valeur_de_%CF%80][méthode de +Monte Carlo sur Wikipédia]]). Le code suivant illustre ce fait : -#+begin_src R :results output graphics :file (org-babel-temp-file "figure" ".png") :exports both :width 600 :height 400 :session *R* +#+begin_src R :results output graphics :file figure_exo1.png :exports both :width 600 :height 400 :session *R* set.seed(42) N = 1000 df = data.frame(X = runif(N), Y = runif(N)) @@ -52,7 +52,7 @@ ggplot(df, aes(x=X,y=Y,color=Accept)) + geom_point(alpha=.2) + coord_fixed() + t #+end_src #+RESULTS: -[[file:/tmp/babel-mEAAPj/figureTP5NNK.png]] +[[file:figure_exo1.png]] 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 : -- 2.18.1