From d83ae4945d8e90045db604e8c9f481619642d307 Mon Sep 17 00:00:00 2001 From: cc04d6c622240218f9bdfa852287cc7d Date: Mon, 8 Mar 2021 22:15:09 +0000 Subject: [PATCH] typos, export results, code entre dollars --- module2/exo1/toy_document_orgmode_R_fr.org | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/module2/exo1/toy_document_orgmode_R_fr.org b/module2/exo1/toy_document_orgmode_R_fr.org index 54b333e..419bb39 100644 --- a/module2/exo1/toy_document_orgmode_R_fr.org +++ b/module2/exo1/toy_document_orgmode_R_fr.org @@ -1,8 +1,6 @@ -#+TITLE: À propos du calcul de \pi +#+TITLE: À propos du calcul de $\pi$ #+LANGUAGE: fr -#+AUTHOR: Arnaud Legrand -#+DATE: 2018-09-19 mer. 21:51 -# #+PROPERTY: header-args :eval never-export +# #+PROPERTY: header-args :session :exports both #+HTML_HEAD: #+HTML_HEAD: @@ -13,7 +11,7 @@ * En demandant à la lib maths -Mon ordinateur m’indique que \pi vaut /approximativement/ +Mon ordinateur m’indique que $\pi$ vaut /approximativement/ #+begin_src R :results output :exports both pi @@ -34,23 +32,26 @@ theta = pi/2*runif(N) * 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[X^2 + Y^2 \inf 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 Wikipedia]]). Le code +à 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 \leq 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 Wikipedia]]). Le code suivant illustre ce fait : -#+begin_src R :results output graphics :exports both :width 600 :height 400 :session *R* +#+begin_src R :results output graphics :file example.png :exports both :width 600 :height 400 :session *R* set.seed(42) N = 1000 df = data.frame(X = runif(N), Y = runif(N)) df$Accept = (df$X**2 <=1= library(ggplot2) -ggplot(df, aes(x=X,y=Y, color=Accept)) + geom_point(alpha=.2) + coold_fixed() + theme_bw() +ggplot(df, aes(x=X,y=Y, color=Accept)) + geom_point(alpha=.2) + coord_fixed() + theme_bw() #+end_src -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 : +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 : #+begin_src R :results output :session *R* :exports both 4*mean(df$Accept) #+end_src + +#+AUTHOR: Arnaud Legrand +#+DATE: 2018-09-19 mer. 21:51 -- 2.18.1