diff --git a/module2/exo1/toy_notebook_en.ipynb b/module2/exo1/toy_notebook_en.ipynb index e58cc6f545a1b82b18f576ddddfe4176b3fa7b1e..3f97c46718674710ebae7303e591a09e625bae3d 100644 --- a/module2/exo1/toy_notebook_en.ipynb +++ b/module2/exo1/toy_notebook_en.ipynb @@ -4,22 +4,26 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# On the computation of $\\pi$" + "# On the computation of $\\pi$" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "hideCode": false + }, "source": [ "## Asking the maths library\n", - "\n", "My computer tells me that π is *approximatively*" ] }, { "cell_type": "code", "execution_count": 1, - "metadata": {}, + "metadata": { + "hideCode": false, + "hidePrompt": false + }, "outputs": [ { "name": "stdout", @@ -36,17 +40,21 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "hidePrompt": false + }, "source": [ "## Buffon's needle\n", - "\n", "Applying the method of [Buffon’s needle](https://en.wikipedia.org/wiki/Buffon%27s_needle_problem), we get the **approximation**" ] }, { "cell_type": "code", "execution_count": 2, - "metadata": {}, + "metadata": { + "hideCode": false, + "hidePrompt": false + }, "outputs": [ { "data": { @@ -70,10 +78,11 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "hideCode": false + }, "source": [ "## Using a surface fraction argument\n", - "\n", "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:" ] }, @@ -98,11 +107,12 @@ "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", - "1\n", + "\n", "accept = (x*x+y*y) <= 1\n", "reject = np.logical_not(accept)\n", "fig, ax = plt.subplots(1)\n", @@ -137,16 +147,10 @@ "source": [ "4*np.mean(accept)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { + "celltoolbar": "Hide code", "kernelspec": { "display_name": "Python 3", "language": "python", @@ -162,7 +166,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.4" + "version": "3.6.2" } }, "nbformat": 4,