From 91f8a1c7e1249af010407c22b7d984ff0918c05e Mon Sep 17 00:00:00 2001 From: ce14f10f5bc5e484777f1060f8856ea9 Date: Tue, 7 Jun 2022 11:57:11 +0000 Subject: [PATCH] finished, try 1 --- module2/exo1/toy_notebook_en.ipynb | 35 ++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/module2/exo1/toy_notebook_en.ipynb b/module2/exo1/toy_notebook_en.ipynb index 31778b1..edd1f0e 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, -- 2.18.1