no commit message

parent 638b04aa
......@@ -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 (<ipython-input-7-8cfaff9333ae>, line 2)",
"evalue": "invalid syntax (<ipython-input-12-78e089221e89>, line 2)",
"output_type": "error",
"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": [
"## 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,
......
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