#+begin_src python :results file :session :var matplot_lib_filename="figure.png" :exports both
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\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 python :exports both :results output file :session :var matplot_lib_filename="./figure.png"
import matplotlib.pyplot as plt
...
...
@@ -138,7 +56,18 @@ ax.set_aspect('equal')
plt.savefig(matplot_lib_filename)
print(matplot_lib_filename)
#+end_src
#+end_src
#+RESULTS:
[[file:<matplotlib.collections.PathCollection object at 0x7f8ea60c6be0>]]
[[file:./figure.png]]
Il est alors aisé d'obtenir une approximation (pas terrible) de π en comptant combien de fois,