module 2 exercise 1 - fixes

parent 9ac75620
......@@ -12,7 +12,7 @@
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/readtheorg/js/readtheorg.js"></script>
* 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 *
pi
......@@ -22,7 +22,8 @@ pi
: 3.141592653589793
* Buffon's needle
Applying the method of [[https://en.wikipedia.org/wiki/Buffon%27s_needle_problem][Buffon's]] needle, we get the approximation
Applying the method of
[[https://en.wikipedia.org/wiki/Buffon%27s_needle_problem][Buffon's needle]], we get the *approximation*
#+begin_src python :results value :session *python* :exports both
import numpy as np
......@@ -44,9 +45,7 @@ then $P[X^2+Y^2 \le 1]=\pi/4$ (see
method" on Wikipedia]]). The following code uses this approach:
#+begin_src python :results output :session *python* :var matplot_lib_filename="figure.png" :exports code
#+begin_src python :results output file :session *python* :var matplot_lib_filename="figure.png" :exports both
import matplotlib.pyplot as plt
np.random.seed(seed=42)
......@@ -67,18 +66,21 @@ print(matplot_lib_filename)
#+end_src
#+RESULTS:
: figure.png
[[file:figure.png]]
[[./figure.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 value :session *python* :exports both
#+begin_src python :results output :session *python* :exports both
4*np.mean(accept)
#+end_src
#+RESULTS:
: 3.112
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