From 25820bafd0cb5e957a0ebf936d8e8ec90e44201c Mon Sep 17 00:00:00 2001 From: Victor-M-Gomes Date: Tue, 28 Apr 2020 12:02:09 +0200 Subject: [PATCH] Commit exo1 module2 --- .../exo1/toy_document_orgmode_python_en.html | 28 +++++++++---------- .../exo1/toy_document_orgmode_python_en.org | 6 ++-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/module2/exo1/toy_document_orgmode_python_en.html b/module2/exo1/toy_document_orgmode_python_en.html index cff6770..013d0eb 100644 --- a/module2/exo1/toy_document_orgmode_python_en.html +++ b/module2/exo1/toy_document_orgmode_python_en.html @@ -4,7 +4,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + On the computation of pi @@ -248,17 +248,17 @@

Table of Contents

-
-

1 Asking the math library

+
+

1 Asking the math library

-My computer tells me that π is approximatively +My computer tells me that \(\pi\) is approximatively

@@ -273,8 +273,8 @@ pi
-
-

2 * Buffon’s needle

+
+

2 * Buffon’s needle

Applying the method of Buffon’s needle, we get the approximation @@ -295,11 +295,11 @@ np.random.seed(seed=42)

-
-

3 Using a surface fraction argument

+
+

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 \approx U(0,1)\) and \(Y \approx U(0,1)\), then \(P[X^2 + Y^2 \leq 1] = \pi/4\) (see “Monte Carlo method on Wikipedia”). The following code uses this approach: +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 “Monte Carlo method” on Wikipedia). The following code uses this approach:

import matplotlib.pyplot as plt
@@ -330,7 +330,7 @@ plt.savefig(matplot_lib_filename)
 
 
 

-It is then straightforward to obtain a (not really good) approximation to π by counting how many times, on average, \(X^2 + Y^2\) is smaller than 1: +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:

4*np.mean(accept)
@@ -345,7 +345,7 @@ It is then straightforward to obtain a (not really good) approximation to π b
 

Author: Victor Martins Gomes

-

Created: 2020-04-28 mar. 11:54

+

Created: 2020-04-28 mar. 12:01

diff --git a/module2/exo1/toy_document_orgmode_python_en.org b/module2/exo1/toy_document_orgmode_python_en.org index 6b25924..c01b752 100644 --- a/module2/exo1/toy_document_orgmode_python_en.org +++ b/module2/exo1/toy_document_orgmode_python_en.org @@ -2,7 +2,7 @@ #+LANGUAGE: en # #+PROPERTY: header-args :session :exports both * Asking the math library -My computer tells me that \pi is approximatively +My computer tells me that $\pi$ is /approximatively/ #+begin_src python :results value :session *python* :exports both from math import * @@ -27,7 +27,7 @@ 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 \approx U(0,1)$ and $Y \approx 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 code uses this approach: +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 code uses this approach: #+begin_src python :results output file :var matplot_lib_filename="figure_pi_mc2.png" :exports both :session *python* import matplotlib.pyplot as plt @@ -52,7 +52,7 @@ print(matplot_lib_filename) [[file:figure_pi_mc2.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: +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 4*np.mean(accept) #+end_src -- 2.18.1