From 47804a89a1d6f02f7b231e195e449369994cf029 Mon Sep 17 00:00:00 2001 From: Corentin Ambroise Date: Tue, 2 Mar 2021 22:02:02 +0100 Subject: [PATCH] exo1 --- exo1/.DS_Store | Bin 0 -> 6148 bytes exo1/.html | 252 ++++++++++++++ exo1/matplot_lib_filename | 1 + exo1/toy_document_orgmode_python_fr.html | 380 +++++++++++++++++++++ exo1/toy_document_orgmode_python_fr.html~ | 381 ++++++++++++++++++++++ exo1/toy_document_orgmode_python_fr.org | 68 ++++ exo1/toy_document_orgmode_python_fr.org~ | 71 ++++ 7 files changed, 1153 insertions(+) create mode 100644 exo1/.DS_Store create mode 100644 exo1/.html create mode 100644 exo1/matplot_lib_filename create mode 100644 exo1/toy_document_orgmode_python_fr.html create mode 100644 exo1/toy_document_orgmode_python_fr.html~ create mode 100644 exo1/toy_document_orgmode_python_fr.org create mode 100644 exo1/toy_document_orgmode_python_fr.org~ diff --git a/exo1/.DS_Store b/exo1/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 + + + + + + + + + + + + + +
+
+
+

Author: Corentin Ambroise

+

Created: 2021-03-02 Mar 21:04

+

Validate

+
+ + diff --git a/exo1/matplot_lib_filename b/exo1/matplot_lib_filename new file mode 100644 index 0000000..6f69051 --- /dev/null +++ b/exo1/matplot_lib_filename @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/exo1/toy_document_orgmode_python_fr.html b/exo1/toy_document_orgmode_python_fr.html new file mode 100644 index 0000000..858abf2 --- /dev/null +++ b/exo1/toy_document_orgmode_python_fr.html @@ -0,0 +1,380 @@ + + + + + + + +À 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∼U(0,1)\) et \(Y∼U(0,1)\) alors \(P[X2+Y2≤1]=π/4\) +

+ +

+(voir méthode de 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)
+print(matplot_lib_filename)
+
+
+ + +
+

figureg0ckjn.png +

+
+ +

+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 : +

+
+
print(4*np.mean(accept))
+
+
+ +
+3.112
+
+
+
+
+
+

Author: Konrad Hinsen

+

Created: 2021-03-02 Mar 22:00

+

Validate

+
+ + diff --git a/exo1/toy_document_orgmode_python_fr.html~ b/exo1/toy_document_orgmode_python_fr.html~ new file mode 100644 index 0000000..9a48af0 --- /dev/null +++ b/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∼U(0,1)\) et \(Y∼U(0,1)\) alors \(P[X2+Y2≤1]=π/4\) +

+ +

+(voir méthode de 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)
+print(matplot_lib_filename)
+matplot_lib_filename
+
+
+ + +
+

figureAWIivO.png +

+
+ +

+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 : +

+
+
print(4*np.mean(accept))
+
+
+ +
+3.112
+
+
+
+
+
+

Author: Konrad Hinsen

+

Created: 2021-03-02 Mar 21:59

+

Validate

+
+ + diff --git a/exo1/toy_document_orgmode_python_fr.org b/exo1/toy_document_orgmode_python_fr.org new file mode 100644 index 0000000..a5af7e2 --- /dev/null +++ b/exo1/toy_document_orgmode_python_fr.org @@ -0,0 +1,68 @@ +#+TITLE: À propos du calcul de π +#+AUTHOR: Konrad Hinsen + +* En demandant à la lib maths + +Mon ordinateur m'indique que π vaut /approximativement/: +#+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 value :session :exports both +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) +#+end_src + +#+RESULTS: +: 3.128911138923655 + +* 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∼U(0,1)$ et $Y∼U(0,1)$ alors $P[X2+Y2≤1]=π/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=(org-babel-temp-file "figure" ".png") :exports both +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) +print(matplot_lib_filename) +#+end_src + +#+RESULTS: +[[file:/var/folders/87/c7x20gt17rjfzcgh427wbtpr0000gn/T/babel-baqYxQ/figureKMPltU.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 : +#+begin_src python :results output :session :exports both +print(4*np.mean(accept)) +#+end_src + +#+RESULTS: +: 3.112 diff --git a/exo1/toy_document_orgmode_python_fr.org~ b/exo1/toy_document_orgmode_python_fr.org~ new file mode 100644 index 0000000..1b26e51 --- /dev/null +++ b/exo1/toy_document_orgmode_python_fr.org~ @@ -0,0 +1,71 @@ +#+TITLE: À propos du calcul de π +#+AUTHOR: Konrad Hinsen +#+DATE: 2021-03-02 Tues 20:12 + +* En demandant à la lib maths + +Mon ordinateur m'indique que $π$ vaut /approximativement/: +#+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 value :session :exports both +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) +#+end_src + +#+RESULTS: +: 3.128911138923655 + +* 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∼U(0,1)$ et $Y∼U(0,1)$ alors $P[X2+Y2≤1]=π/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=(org-babel-temp-file "figure" ".png") :exports both +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) +print(matplot_lib_filename) +#+end_src + +#+RESULTS: +[[file:]] + +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 : +#+begin_src python :results output :session :exports both +print(4*np.mean(accept)) +#+end_src + +#+RESULTS: +: 3.112 + +Validate -- 2.18.1