From d9949f83e637b0e2a1d6b8459656d2248b438b93 Mon Sep 17 00:00:00 2001 From: 8057a7ae58e587eb7d45460ceced4594 <8057a7ae58e587eb7d45460ceced4594@app-learninglab.inria.fr> Date: Thu, 23 Sep 2021 17:55:24 +0000 Subject: [PATCH] final changes --- module2/exo1/toy_notebook_en.ipynb | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/module2/exo1/toy_notebook_en.ipynb b/module2/exo1/toy_notebook_en.ipynb index 9be2a9e..2c82fd7 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')" -- 2.18.1