From 362372f285b590a5106ccb3e5ef8f6aab5cda267 Mon Sep 17 00:00:00 2001 From: Dorinel Bastide Date: Tue, 7 Jul 2020 22:47:32 +0200 Subject: [PATCH] Third attempt, cosmetic changes --- .../exo1/toy_document_orgmode_python_en.org | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/module2/exo1/toy_document_orgmode_python_en.org b/module2/exo1/toy_document_orgmode_python_en.org index 6c66c86..5e6d2ae 100644 --- a/module2/exo1/toy_document_orgmode_python_en.org +++ b/module2/exo1/toy_document_orgmode_python_en.org @@ -1,8 +1,5 @@ -#+TITLE: On the computation of pi -#+AUTHOR: Dorinel Bastide -#+DATE: Today's date +#+TITLE: On the computation of pi #+LANGUAGE: en -# #+PROPERTY: header-args :eval never-export #+HTML_HEAD: #+HTML_HEAD: @@ -40,14 +37,13 @@ theta = np.random.uniform(size=N, low=0, high=pi/2) : 3.128911138923655 * 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 +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 :var matplot_lib_filename="C:/Users/Utilisateur/mooc-rr/module2/exo1/PictureRes.png" :exports both :session *python* import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt -import numpy as np np.random.seed(seed=42) N = 1000 x = np.random.uniform(size=N, low=0, high=1) @@ -70,10 +66,9 @@ print(matplot_lib_filename) Type "help", "copyright", "credits" or "license" for more information. C:/Users/Utilisateur/mooc-rr/module2/exo1/PictureRes.png]] -It is then straightforward to obtain a (not really good) approximation -to $\pi$ by counting how many times, on average, $X^2 + Y^2$ is smaller -than $1$: -#+begin_src python :results output :exports both +It is then straightforward to obtain a (not really good) approximation to $\pi$ by counting how many times, on average, $X^2 + Y^2$ is smaller than 1: + +#+begin_src python :results output :session *python* :exports both import numpy as np 4*np.mean(accept) #+end_src -- 2.18.1