Sinon, une méthode plus simple à comprendre et ne faisant pas intervenir d'appel
@@ -374,7 +374,7 @@ combien de fois, en moyenne, \(X^2+Y^2\) est inférieur à 1 :
Date: 01/04/2020
Auteur: Clément
-
Created: 2020-04-01 Wed 10:17
+
Created: 2020-04-01 Wed 10:20
Validate
diff --git a/module2/exo1/toy_document_orgmode_python_fr.html~ b/module2/exo1/toy_document_orgmode_python_fr.html~
new file mode 100644
index 0000000000000000000000000000000000000000..b5c79300c47b72eded04f42922b8781438556f10
--- /dev/null
+++ b/module2/exo1/toy_document_orgmode_python_fr.html~
@@ -0,0 +1,381 @@
+
+
+
+
+
+
+
+
À propos du calcul de π
+
+
+
+
+
+
+
+
+
+
+
+
+
+
À propos du calcul de π
+
+
+
+
1 En demandant à la lib maths
+
+
+Mon ordinateur m'indique que π vaut approximativement :
+
+
+
+
from math import *
+pi
+
+
+
+
+3.141592653589793
+
+
+
+
+
+
2 En utilisant la méthode des aiguilles de Buffon
+
+
+Mais calculé avec la méthode des aiguilles de Buffon, on obtiendrait comme
+approximation :
+
+
+
+
import numpy as np
+np.random.seed(seed=42)
+N = 10000
+x = np.random.uniform(size=N, low=0, high=1)
+theta = np.random.uniform(size=N, low=0, high=pi/2)
+2/(sum((x+np.sin(theta))>1)/N)
+
+
+
+
+3.128911138923655
+
+
+
+
+
+
3 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
+méthode
+yde Monte Carlo sur Wikipedia). Le code suivant illustre ce fait :
+
+
+
+
import matplotlib.pyplot as plt
+
+np.random.seed(seed=42)
+N = 1000
+x = np.random.uniform(size=N, low=0, high=1)
+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)
+ax.set_aspect('equal')
+
+plt.savefig(matplot_lib_filename)
+matplot_lib_filename
+
+
+
+
+
+Il est alors aisé d'obtenir une approximation (pas terrible) de π en comptant
+combien de fois, en moyenne, \(X^2+Y^2\) est inférieur à 1 :
+
+
+
+
+3.112
+
+
+
+
+
+
Date: 01/04/2020
+
Auteur: Clément
+
Created: 2020-04-01 Wed 10:17
+
Validate
+
+
+
diff --git a/module2/exo2/data.txt b/module2/exo2/data.txt
new file mode 100644
index 0000000000000000000000000000000000000000..e965fb5ef4fc217f5b214bfaa0f1181eadf057f1
--- /dev/null
+++ b/module2/exo2/data.txt
@@ -0,0 +1 @@
+14.0, 7.6, 11.2, 12.8, 12.5, 9.9, 14.9, 9.4, 16.9, 10.2, 14.9, 18.1, 7.3, 9.8, 10.9,12.2, 9.9, 2.9, 2.8, 15.4, 15.7, 9.7, 13.1, 13.2, 12.3, 11.7, 16.0, 12.4, 17.9, 12.2, 16.2, 18.7, 8.9, 11.9, 12.1, 14.6, 12.1, 4.7, 3.9, 16.9, 16.8, 11.3, 14.4, 15.7, 14.0, 13.6, 18.0, 13.6, 19.9, 13.7, 17.0, 20.5, 9.9, 12.5, 13.2, 16.1, 13.5, 6.3, 6.4, 17.6, 19.1, 12.8, 15.5, 16.3, 15.2, 14.6, 19.1, 14.4, 21.4, 15.1, 19.6, 21.7, 11.3, 15.0, 14.3, 16.8, 14.0, 6.8, 8.2, 19.9, 20.4, 14.6, 16.4, 18.7, 16.8, 15.8, 20.4, 15.8, 22.4, 16.2, 20.3, 23.4, 12.1, 15.5, 15.4, 18.4, 15.7, 10.2, 8.9, 21.0
diff --git a/module2/exo2/exercice_python_fr.org b/module2/exo2/exercice_python_fr.org
index c7157ba42216cf2e1d291112bb351ce48811115c..cb38c4706f370f893e2f19413599280009ee24fe 100644
--- a/module2/exo2/exercice_python_fr.org
+++ b/module2/exo2/exercice_python_fr.org
@@ -11,7 +11,28 @@
#+HTML_HEAD:
#+HTML_HEAD:
-* Quelques explications
+
+
+#+begin_src python :results output :session :exports both
+import numpy as np
+
+data = [14.0, 7.6, 11.2, 12.8, 12.5, 9.9, 14.9, 9.4, 16.9, 10.2, 14.9, 18.1, 7.3, 9.8, 10.9,12.2, 9.9, 2.9, 2.8, 15.4, 15.7, 9.7, 13.1, 13.2, 12.3, 11.7, 16.0, 12.4, 17.9, 12.2, 16.2, 18.7, 8.9, 11.9, 12.1, 14.6, 12.1, 4.7, 3.9, 16.9, 16.8, 11.3, 14.4, 15.7, 14.0, 13.6, 18.0, 13.6, 19.9, 13.7, 17.0, 20.5, 9.9, 12.5, 13.2, 16.1, 13.5, 6.3, 6.4, 17.6, 19.1, 12.8, 15.5, 16.3, 15.2, 14.6, 19.1, 14.4, 21.4, 15.1, 19.6, 21.7, 11.3, 15.0, 14.3, 16.8, 14.0, 6.8, 8.2, 19.9, 20.4, 14.6, 16.4, 18.7, 16.8, 15.8, 20.4, 15.8, 22.4, 16.2, 20.3, 23.4, 12.1, 15.5, 15.4, 18.4, 15.7, 10.2, 8.9, 21.0]
+
+print("Average: "+str(np.average(data)))
+print("Std: "+str(np.std(data, ddof=1)))
+print("Min: "+str(np.min(data)))
+print("Max: "+str(np.max(data)))
+print("Median: "+str(np.median(data)))
+#+end_src
+
+#+RESULTS:
+: Average: 14.113000000000001
+: Std: 4.334094455301447
+: Min: 2.8
+: Max: 23.4
+: Median: 14.5
+
+* Quelques explications :noexport:
Ceci est un document org-mode avec quelques exemples de code
python. Une fois ouvert dans emacs, ce document peut aisément être
diff --git a/module2/exo3/exercice_python_fr.org b/module2/exo3/exercice_python_fr.org
index c7157ba42216cf2e1d291112bb351ce48811115c..6c40189c3381784a1862444c24af687f0f0cf0da 100644
--- a/module2/exo3/exercice_python_fr.org
+++ b/module2/exo3/exercice_python_fr.org
@@ -11,7 +11,47 @@
#+HTML_HEAD:
#+HTML_HEAD:
-* Quelques explications
+#+begin_src python :results file :session :var matplot_lib_filename=(org-babel-temp-file "figure1" ".png") :exports both
+import matplotlib.pyplot as plt
+
+import numpy
+
+data = [14.0, 7.6, 11.2, 12.8, 12.5, 9.9, 14.9, 9.4, 16.9, 10.2, 14.9, 18.1, 7.3, 9.8, 10.9,12.2, 9.9, 2.9, 2.8, 15.4, 15.7, 9.7, 13.1, 13.2, 12.3, 11.7, 16.0, 12.4, 17.9, 12.2, 16.2, 18.7, 8.9, 11.9, 12.1, 14.6, 12.1, 4.7, 3.9, 16.9, 16.8, 11.3, 14.4, 15.7, 14.0, 13.6, 18.0, 13.6, 19.9, 13.7, 17.0, 20.5, 9.9, 12.5, 13.2, 16.1, 13.5, 6.3, 6.4, 17.6, 19.1, 12.8, 15.5, 16.3, 15.2, 14.6, 19.1, 14.4, 21.4, 15.1, 19.6, 21.7, 11.3, 15.0, 14.3, 16.8, 14.0, 6.8, 8.2, 19.9, 20.4, 14.6, 16.4, 18.7, 16.8, 15.8, 20.4, 15.8, 22.4, 16.2, 20.3, 23.4, 12.1, 15.5, 15.4, 18.4, 15.7, 10.2, 8.9, 21.0]
+
+x=numpy.linspace(-15,15)
+plt.figure(figsize=(10,5))
+plt.plot(data)
+plt.tight_layout()
+
+plt.savefig(matplot_lib_filename)
+matplot_lib_filename
+
+#+end_src
+
+#+RESULTS:
+[[file:/tmp/babel-AQqtCi/figureR2yZWS.png]]
+
+#+begin_src python :results file :session :var matplot_lib_filename=(org-babel-temp-file "figurehist" ".png") :exports both
+import matplotlib.pyplot as plt
+
+import numpy
+
+x=numpy.linspace(-15,15)
+plt.figure(figsize=(10,5))
+plt.hist(data, facecolor='blue',alpha=0.5, edgecolor='black')
+plt.grid(b='True', linestyle='--')
+plt.tight_layout()
+
+plt.savefig(matplot_lib_filename)
+matplot_lib_filename
+
+#+end_src
+
+#+RESULTS:
+[[file:/tmp/babel-AQqtCi/figurehist6XxvCK.png]]
+
+
+* Quelques explications :noexport:
Ceci est un document org-mode avec quelques exemples de code
python. Une fois ouvert dans emacs, ce document peut aisément être