diff --git a/module2/exo1/toy_notebook_en.ipynb b/module2/exo1/toy_notebook_en.ipynb index 31778b196aa3220562b1e9d50f811b163d88e1f8..edd1f0e68fde4fb9d06e52f910f42d018801402e 100644 --- a/module2/exo1/toy_notebook_en.ipynb +++ b/module2/exo1/toy_notebook_en.ipynb @@ -43,16 +43,16 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "2.0" + "3.128911138923655" ] }, - "execution_count": 2, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -63,7 +63,7 @@ "N = 10000\n", "x = np.random.uniform(size=N, low=0, high=1)\n", "theta = np.random.uniform(size=N, low=0, high=pi/2)\n", - "2/(sum(x+np.sin(theta))>1/N)" + "2/(sum((x+np.sin(theta))>1)/N)" ] }, { @@ -109,6 +109,33 @@ "ax.set_aspect('equal')" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It is then straightforward to obtain a (not really good) approximation to $\\pi$ by counting how many times, on average, $X^2+Y^2$ is smaller than 1:" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3.112" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "4*np.mean(accept)" + ] + }, { "cell_type": "code", "execution_count": null,