diff --git a/module2/exo1/toy_document_orgmode_R_fr.org b/module2/exo1/toy_document_orgmode_R_fr.org index 75845eb37ae449f67e7182088daa3fa51dbf207b..82cc05fdc3d1892a7794a97bcecdd4615a07413b 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 69757e935602d26cf372c6b3f3f4c0f3eb6639a1..8bc916215eff97db2157703af5abab91e25e42f3 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