diff --git a/module2/exo1/toy_document_orgmode_python_fr.org b/module2/exo1/toy_document_orgmode_python_fr.org index 2548e2925864ddf1834d814b507cef5c35455387..63c4d389fb9bd08f23782d3dc3272106a847dd04 100644 --- a/module2/exo1/toy_document_orgmode_python_fr.org +++ b/module2/exo1/toy_document_orgmode_python_fr.org @@ -1,4 +1,4 @@ -#+TITLE: À propos du calcul de $\pi$ +ho#+TITLE: À propos du calcul de $\pi$ #+LANGUAGE: fr @@ -41,8 +41,7 @@ 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^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 output file :var matplot_lib_filename="figure_pi_mc2.png" :exports both :session *python* +#+begin_src python :results file :session :var matplot_lib_filename=(org-babel-temp-file "figure" ".png") :exports both import matplotlib.pyplot as plt np.random.seed(seed=42) @@ -59,15 +58,11 @@ ax.scatter(x[reject], y[reject], c='r', alpha=0.2, edgecolor=None) ax.set_aspect('equal') plt.savefig(matplot_lib_filename) -print(matplot_lib_filename) +matplot_lib_filename #+end_src #+RESULTS: -[[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]] +[[file:/var/folders/21/wtvjlyxj21b3gj703l4k0j_40000gp/T/babel-0OJhDQ/figureX0cFtl.png]] 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 :