diff --git a/module2/exo1/toy_document_orgmode_python_en.org b/module2/exo1/toy_document_orgmode_python_en.org index 9e167bee5f8a94cb6bd481211fe3713d592f3458..6c66c86517ecf4f823a8472aeb7dcc636e5bcd50 100644 --- a/module2/exo1/toy_document_orgmode_python_en.org +++ b/module2/exo1/toy_document_orgmode_python_en.org @@ -11,42 +11,36 @@ #+HTML_HEAD: #+HTML_HEAD: -* Table of Contents +#+PROPERTY: header-args :session :exports both -1. Asking the math libraryo -2. * Buffon's needle -3. Using a surface fraction argument - -* 1 Asking the math library +* Asking the math library My computer tells me that $\pi$ is /approximatively/ -#+begin_src python :results output :exports both -import math -print(math.pi) +#+begin_src python :results value :session *python* :exports both +from math import * +pi #+end_src #+RESULTS: : 3.141592653589793 -* 2 * Buffon's needle -Applying the method of [[https://en.wikipedia.org/wiki/Buffon%27s_needle_problem][Buffon's needle]], we get the approximation +* * Buffon's needle +Applying the method of [[https://en.wikipedia.org/wiki/Buffon%27s_needle_problem][Buffon's needle]], we get the *approximation* -#+begin_src python :results output :exports both -import math +#+begin_src python :results value :session *python* :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=math.pi/2) -print(2/(sum((x+np.sin(theta))>1)/N)) +theta = np.random.uniform(size=N, low=0, high=pi/2) +2/(sum((x+np.sin(theta))>1)/N) #+end_src #+RESULTS: : 3.128911138923655 -* 3. Using a surface fraction argument -A method that is easier to understand and does not make use of the - $\sin$ function is based on the fact that if $X\sim U(0,1)$ and $Y\sim +* Using a surface fraction argument +A method that is easier to understand and does not make use of the $\sin$ function is based on the fact that if $X\sim U(0,1)$ and $Y\sim U(0,1)$, then $P[X^2 + Y^2 \leq 1]=\pi/4$ (see [[https://en.wikipedia.org/wiki/Monte_Carlo_method]["Monte Carlo method" on Wikipedia]]). The following ocde uses this approach: #+begin_src python :results output file :session :var matplot_lib_filename="C:/Users/Utilisateur/mooc-rr/module2/exo1/PictureRes.png" :exports results