no commit message

parent 638b04aa
...@@ -6,15 +6,17 @@ ...@@ -6,15 +6,17 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"## toy_notebook_en\n", "# On the computation of $\\pi$"
"\n", ]
"March 28, 2019 \n", },
"\n", {
"# On the computation of π\n", "cell_type": "code",
"\n", "execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"## Asking the maths library\n", "## Asking the maths library\n",
"\n", "My computer tells me that $\\pi$ is *approximatively*"
"My computer tells me that π is approximatively"
] ]
}, },
{ {
...@@ -37,26 +39,27 @@ ...@@ -37,26 +39,27 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 12,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"ename": "SyntaxError", "ename": "SyntaxError",
"evalue": "invalid syntax (<ipython-input-7-8cfaff9333ae>, line 2)", "evalue": "invalid syntax (<ipython-input-12-78e089221e89>, line 2)",
"output_type": "error", "output_type": "error",
"traceback": [ "traceback": [
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-7-8cfaff9333ae>\"\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\"<ipython-input-12-78e089221e89>\"\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": [ "source": [
"## Buffon’s needle\n", "## Buffon's needle\n",
"Applying the method of Buffon’s needle, we get the approximation\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", "cell_type": "code",
"execution_count": 5, "execution_count": 13,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -65,7 +68,7 @@ ...@@ -65,7 +68,7 @@
"3.128911138923655" "3.128911138923655"
] ]
}, },
"execution_count": 5, "execution_count": 13,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -80,7 +83,6 @@ ...@@ -80,7 +83,6 @@
"x = np.random.uniform(size=N, low=0, high=1)\n", "x = np.random.uniform(size=N, low=0, high=1)\n",
"\n", "\n",
"theta = np.random.uniform(size=N, low=0, high=pi/2)\n", "theta = np.random.uniform(size=N, low=0, high=pi/2)\n",
"\n",
"2/(sum((x+np.sin(theta))>1)/N)\n" "2/(sum((x+np.sin(theta))>1)/N)\n"
] ]
}, },
...@@ -91,9 +93,11 @@ ...@@ -91,9 +93,11 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"## Using a surface fraction argument\n", "## 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", "A method that is easier to understand and does not make use of the $\\sin$\n",
"fact that if X ∼ U(0, 1) and Y ∼ U(0, 1), then P[X2 + Y2 ≤ 1] = π/4 (see \"Monte Carlo method\"\n", "function is based on the fact that if $X\\sim U(0,1)$ and $Y\\sim U(0,1)$, \n",
"on Wikipedia). The following code uses this approach:" "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 @@ ...@@ -136,8 +140,8 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"It is then straightforward to obtain a (not really good) approximation to π by counting how\n", "It is then straightforward to obtain a (not really good) approximation to $\\pi$ \n",
"many times, on average, X2 + Y2 is smaller than 1:" "by counting how many times, on average, $X^2 + Y^2$ is smaller than 1:"
] ]
}, },
{ {
...@@ -160,6 +164,13 @@ ...@@ -160,6 +164,13 @@
" 4*np.mean(accept)" " 4*np.mean(accept)"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment