From a645391babeeb841d1949070d0c4bba7b48cb850 Mon Sep 17 00:00:00 2001 From: 8057a7ae58e587eb7d45460ceced4594 <8057a7ae58e587eb7d45460ceced4594@app-learninglab.inria.fr> Date: Thu, 23 Sep 2021 17:49:08 +0000 Subject: [PATCH] minor changes --- module2/exo1/toy_notebook_en.ipynb | 36 +++++++----------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/module2/exo1/toy_notebook_en.ipynb b/module2/exo1/toy_notebook_en.ipynb index 03952de..90c97c5 100644 --- a/module2/exo1/toy_notebook_en.ipynb +++ b/module2/exo1/toy_notebook_en.ipynb @@ -4,20 +4,10 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# On the computation of $\\pi$" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Asking the maths library" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ + "# On the computation of $\\pi$\n", + "\n", + "## Asking the maths library\n", + "\n", "My computer tells me that $\\pi$ is *approximatively*" ] }, @@ -82,13 +72,8 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Using a surface fraction argument" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ + "## Using a surface fraction argument\n", + "\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:" ] }, @@ -113,12 +98,14 @@ "source": [ "%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", "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", @@ -151,13 +138,6 @@ "source": [ "4*np.mean(accept)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { -- 2.18.1