diff --git a/module2/exo1/toy_notebook_en.ipynb b/module2/exo1/toy_notebook_en.ipynb index 9be2a9e32c805f7d49f84a79216e95c4c9fcb481..2c82fd797801c246e796c2de525a868fce70f7df 100644 --- a/module2/exo1/toy_notebook_en.ipynb +++ b/module2/exo1/toy_notebook_en.ipynb @@ -4,7 +4,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# On the computation of $\\pi$\n", + "# On the computation of $\\pi$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ "## Asking the maths library\n", "My computer tells me that $\\pi$ is *approximatively*" ] @@ -32,7 +38,7 @@ "metadata": {}, "source": [ "## Buffon's needle\n", - "Applying the method of [Buffon's needle](https://en.wikipedia.org/wiki/Buffon%27s_needle_problem), we get the **approximation**" + "Applying the method of [Buffon's needle](https://en.wikipedia.org/wiki/Buffon%27s_needle_problem), we get the _approximation_" ] }, { @@ -65,7 +71,7 @@ "metadata": {}, "source": [ "## Using a surface fraction argument\n", - "A method that is easier to understand and does not make use of thesin function is based on thefact that if $X \\sim U(0,1)$ and $Y \\sim U(0,1)$, then $P[X^2 + Y^2 \\leq 1] = \\frac{\\pi}{4}$ (see [\"Monte Carlo method\" on Wikipedia](https://en.wikipedia.org/wiki/Monte_Carlo_method). 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](https://en.wikipedia.org/wiki/Monte_Carlo_method)). The following code uses this approach:" ] }, { @@ -87,17 +93,18 @@ } ], "source": [ - "%matplotlib inline\n", + "%matplotlib inline \n", "import matplotlib.pyplot as plt\n", "\n", "np.random.seed(seed=42)\n", - "N=1000\n", - "x=np.random.uniform(size=N, low=0, high=1)\n", - "y=np.random.uniform(size=N, low=0, high=1)\n", - "accept=(x*x+y*y)<=1\n", - "reject=np.logical_not(accept)\n", + "N = 1000\n", + "x = np.random.uniform(size=N, low=0, high=1)\n", + "y = np.random.uniform(size=N, low=0, high=1)\n", + "\n", + "accept = (x*x+y*y) <= 1\n", + "reject = np.logical_not(accept)\n", "\n", - "fig, ax=plt.subplots(1)\n", + "fig, ax = plt.subplots(1)\n", "ax.scatter(x[accept], y[accept], c='b', alpha=0.2, edgecolor=None)\n", "ax.scatter(x[reject], y[reject], c='r', alpha=0.2, edgecolor=None)\n", "ax.set_aspect('equal')"