Commit c005bd82 authored by Tommy Rushton's avatar Tommy Rushton

Bring things closer into line with target notebook.

parent 3fcff9f3
#+TITLE: On the computation of pi #+TITLE: On the computation of pi
#+LANGUAGE: en #+LANGUAGE: en
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/htmlize.css"/> #+HTML_HEAD: <link rel="stylesheet" type="text/css" href="http://www.pirilampo.org/styles/readtheorg/css/htmlize.css"/>
...@@ -8,12 +8,10 @@ ...@@ -8,12 +8,10 @@
#+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/lib/js/jquery.stickytableheaders.js"></script>
#+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/readtheorg/js/readtheorg.js"></script> #+HTML_HEAD: <script type="text/javascript" src="http://www.pirilampo.org/styles/readtheorg/js/readtheorg.js"></script>
# #+PROPERTY: header-args :eval never-export # #+PROPERTY: header-args :session :exports both
* Table of Contents
* Asking the math library * 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 :exports both #+begin_src python :results value :session :exports both
from math import * from math import *
...@@ -24,8 +22,7 @@ pi ...@@ -24,8 +22,7 @@ pi
: 3.141592653589793 : 3.141592653589793
* * Buffon's needle * * Buffon's needle
Applying the method of Applying the method of [[https://en.wikipedia.org/wiki/Buffon%2527s_needle_problem][Buffon's needle]], we get the *approximation*
[[https://en.wikipedia.org/wiki/Buffon%2527s_needle_problem][Buffon's needle]] we get the *approximation*
#+begin_src python :results value :session :exports both #+begin_src python :results value :session :exports both
import numpy as np import numpy as np
...@@ -42,10 +39,7 @@ theta = np.random.uniform(size=N, low=0, high=pi/2) ...@@ -42,10 +39,7 @@ theta = np.random.uniform(size=N, low=0, high=pi/2)
* Using a surface fraction argument * Using a surface fraction argument
A method that is easier to understand and does not make use of the A method that is easier to understand and does not make use of the
$\sin$ function is based on the fact that if $X ~ U(0,1)$ and $Y ~ $\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:
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 :session :var matplot_lib_filename="figure_pi_mc2.png" :exports both #+begin_src python :results output file :session :var matplot_lib_filename="figure_pi_mc2.png" :exports both
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
......
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