From 2e8aed7b7c08ac8a3d59a3a5d574b9bf407a83a0 Mon Sep 17 00:00:00 2001 From: Noukben17 Date: Wed, 27 Oct 2021 11:48:19 +0200 Subject: [PATCH] =?UTF-8?q?exo=2002-1=20fait=20et=20mis=20=C3=A0=20jour?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module2/exo1/toy_document_orgmode_python_fr.org | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/module2/exo1/toy_document_orgmode_python_fr.org b/module2/exo1/toy_document_orgmode_python_fr.org index bb25fb4..f292d38 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 +#+TITLE: À propos du calcul de $\pi$ #+AUTHOR: Benoit NOUGANKE #+DATE: 2021-10-27 #+LANGUAGE: fr @@ -15,20 +15,21 @@ * En demandant à la lib maths -Mon ordinateur m'indique que \pi vaut approximativement: +Mon ordinateur m'indique que $\pi$ vaut approximativement: -#+begin_src python :results output :session :exports both +#+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 @@ -44,7 +45,7 @@ theta = np.random.uniform(size=N, low=0, high=pi/2) * Avec un argument "fréquentiel" de surface 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 \leq1]=\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 : +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 \leq1]=\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 :session :var matplot_lib_filename="fig.png" :exports both import matplotlib.pyplot as plt @@ -57,6 +58,7 @@ y = np.random.uniform(size=N, low=0, high=1) accept = (x*x+y*y) <= 1 reject = np.logical_not(accept) + fig, ax = plt.subplots(1) ax.scatter(x[accept], y[accept], c='b', alpha=0.2, edgecolor=None) ax.scatter(x[reject], y[reject], c='r', alpha=0.2, edgecolor=None) @@ -71,7 +73,7 @@ print(matplot_lib_filename) [[file:fig.png]] -Il est alors aisé d'obtenir une approximation (pas terrible) de \pi en +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