Commit 32a618d0 authored by Dorinel Bastide's avatar Dorinel Bastide

Proceeded to changes following comparison with solution

parent d4b18a45
......@@ -11,42 +11,36 @@
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/lib/js/jquery.stickytableheaders.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/readtheorg/js/readtheorg.js"></script>
* 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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment