From 57d3b55022d9b646c4d5bb936313b24d972abcaa Mon Sep 17 00:00:00 2001 From: Olivia Guillin Date: Fri, 24 Apr 2020 19:35:40 +0200 Subject: [PATCH] =?UTF-8?q?Trois=C3=A8me=5Fessai?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module2/exo1/toy_document_orgmode_python_fr.org | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/module2/exo1/toy_document_orgmode_python_fr.org b/module2/exo1/toy_document_orgmode_python_fr.org index 04d6fec..ac83f48 100644 --- a/module2/exo1/toy_document_orgmode_python_fr.org +++ b/module2/exo1/toy_document_orgmode_python_fr.org @@ -21,7 +21,6 @@ pi : 3.141592653589793 * En utilisant la méthode des aiguilles de Buffon - SCHEDULED: <2020-04-24 Ven> 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 value :session :exports both @@ -42,7 +41,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^2+Y^2 \le1] = \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 python :results file :session :var matplot_lib_filename="figure_pi_mc2.png" :exports both +#+begin_src python :results output file :var matplot_lib_filename="figure_pi_mc2.png" :exports both :session *python* import matplotlib.pyplot as plt np.random.seed(seed=42) @@ -63,7 +62,11 @@ print(matplot_lib_filename) #+end_src #+RESULTS: -[[file:]] +[[file:Traceback (most recent call last): + File "", line 1, in + File "/var/folders/21/wtvjlyxj21b3gj703l4k0j_40000gp/T/babel-4uvhkJ/python-bYwGgQ", line 4, in + np.random.seed(seed=42) +NameError: name 'np' is not defined]] 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 : -- 2.18.1