From 52b7352ed95b7afd36d70e3847ea93f1a8e4216c Mon Sep 17 00:00:00 2001 From: fce86f37331553f2221e91a10c9c872e Date: Thu, 26 Nov 2020 06:01:42 +0000 Subject: [PATCH] no commit message --- module2/exo1/toy_notebook_en.ipynb | 53 ++++++++++++++++++------------ 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/module2/exo1/toy_notebook_en.ipynb b/module2/exo1/toy_notebook_en.ipynb index f70029a..7586003 100644 --- a/module2/exo1/toy_notebook_en.ipynb +++ b/module2/exo1/toy_notebook_en.ipynb @@ -6,15 +6,17 @@ "metadata": {}, "outputs": [], "source": [ - "## toy_notebook_en\n", - "\n", - "March 28, 2019 \n", - "\n", - "# On the computation of π\n", - "\n", + "# On the computation of $\\pi$" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "## Asking the maths library\n", - "\n", - "My computer tells me that π is approximatively" + "My computer tells me that $\\pi$ is *approximatively*" ] }, { @@ -37,26 +39,27 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 12, "metadata": {}, "outputs": [ { "ename": "SyntaxError", - "evalue": "invalid syntax (, line 2)", + "evalue": "invalid syntax (, line 2)", "output_type": "error", "traceback": [ - "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m2\u001b[0m\n\u001b[0;31m Applying the method of Buffon’s needle, we get the approximation\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" + "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m2\u001b[0m\n\u001b[0;31m Applying the method of [Buffon's needle](https://en.wikipedia.org/wiki/Buffon%27s_needle_problem), we get the __approximation__\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" ] } ], "source": [ - "## Buffon’s needle\n", - "Applying the method of Buffon’s needle, we get the approximation\n" + "## Buffon's needle\n", + "Applying the method of [Buffon's needle](https://en.wikipedia.org\n", + "/wiki/Buffon%27s_needle_problem), we get the __approximation__\n" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -65,7 +68,7 @@ "3.128911138923655" ] }, - "execution_count": 5, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -80,7 +83,6 @@ "x = np.random.uniform(size=N, low=0, high=1)\n", "\n", "theta = np.random.uniform(size=N, low=0, high=pi/2)\n", - "\n", "2/(sum((x+np.sin(theta))>1)/N)\n" ] }, @@ -91,9 +93,11 @@ "outputs": [], "source": [ "## Using a surface fraction argument\n", - "A method that is easier to understand and does not make use of the sin function is based on the\n", - "fact that if X ∼ U(0, 1) and Y ∼ U(0, 1), then P[X2 + Y2 ≤ 1] = π/4 (see \"Monte Carlo method\"\n", - "on Wikipedia). The following code uses this approach:" + "A method that is easier to understand and does not make use of the $\\sin$\n", + "function is based on the fact that if $X\\sim U(0,1)$ and $Y\\sim U(0,1)$, \n", + "then $P[X^2+Y^2\\leq 1] = \\pi/4$ (see [\"Monte Carlo method\" on Wikipedia]\n", + "(https://en.wikipedia.org/wiki/Monte_Carlo_method)). The following code uses this\n", + "approach:" ] }, { @@ -136,8 +140,8 @@ "metadata": {}, "outputs": [], "source": [ - "It is then straightforward to obtain a (not really good) approximation to π by counting how\n", - "many times, on average, X2 + Y2 is smaller than 1:" + "It is then straightforward to obtain a (not really good) approximation to $\\pi$ \n", + "by counting how many times, on average, $X^2 + Y^2$ is smaller than 1:" ] }, { @@ -160,6 +164,13 @@ " 4*np.mean(accept)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": null, -- 2.18.1