From 181ba0515bea2abbbc5d82ff106798804ace7b0c Mon Sep 17 00:00:00 2001 From: 40b967d450cc73a5ec8d086a42cb7ff3 Date: Tue, 2 Nov 2021 16:31:07 +0100 Subject: [PATCH] Update both toys --- module2/exo1/toy_document_orgmode_R_fr.org | 2 +- module2/exo1/toy_document_orgmode_python_fr.org | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/module2/exo1/toy_document_orgmode_R_fr.org b/module2/exo1/toy_document_orgmode_R_fr.org index 75845eb..82cc05f 100644 --- a/module2/exo1/toy_document_orgmode_R_fr.org +++ b/module2/exo1/toy_document_orgmode_R_fr.org @@ -11,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 :session *R* :exports both pi #+end_src diff --git a/module2/exo1/toy_document_orgmode_python_fr.org b/module2/exo1/toy_document_orgmode_python_fr.org index 69757e9..8bc9162 100644 --- a/module2/exo1/toy_document_orgmode_python_fr.org +++ b/module2/exo1/toy_document_orgmode_python_fr.org @@ -11,20 +11,21 @@ * En demandant à la lib maths -Mon ordinateur m'indique que $\pi$ vaut /approximativement/ -#+begin_src python :results output :session :exports both +Mon ordinateur m'indique que $\pi$ vaut /approximativement/ : +#+begin_src python :results value :session :exports both from math import * pi #+end_src #+RESULTS: +: 3.141592653589793 * 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* : -#+begin_src python :results output :session :exports both +#+begin_src python :results value :session :exports both import numpy as np np.random.seed(seed=42) N = 10000 @@ -34,6 +35,7 @@ theta = np.random.uniform(size=N, low=0, high=pi/2) #+end_src #+RESULTS: +: 3.128911138923655 * Avec un argument "fréquentiel" de surface @@ -42,7 +44,7 @@ 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 python :results file :session :var matplot_lib_filename="figure_exo1_python.png" :exports both +#+begin_src python :results output file :session :var matplot_lib_filename="figure_exo1_python.png" :exports both import matplotlib.pyplot as plt np.random.seed(seed=42) @@ -63,12 +65,12 @@ print(matplot_lib_filename) #+end_src #+RESULTS: -[[file:]] +[[file:figure_exo1_python.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 : -#+begin_src python :results output :session :exports both +#+begin_src python :results value :session :exports both 4*np.mean(accept) #+end_src -- 2.18.1