"My computer tells me that $\\pi$ is *approximatively*"
]
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [
{
{
"ename": "SyntaxError",
"name": "stdout",
"evalue": "invalid syntax (<ipython-input-2-a35a1da2b367>, line 2)",
"output_type": "stream",
"output_type": "error",
"text": [
"traceback": [
"3.141592653589793\n"
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-2-a35a1da2b367>\"\u001b[0;36m, line \u001b[0;32m2\u001b[0m\n\u001b[0;31m My computer tells me that $\\pi$ is *approximatively*\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
]
]
}
}
],
],
"source": [
"source": [
"## Asking the maths library\n",
"from math import *\n",
"##My computer tells me that $\\pi$ is *approximatively*"
"print(pi)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Buffon's needle\n",
"Applying the method of [Buffon's needle](https://en.wikipedia.org/wiki/Buffon%27s_needle_problem), we get the __approximation__"
"A method that is easier to understand and does not make use of the $\\sin$ function is based on the fact that if $X\\sim U(0,1)$ and $Y\\sim U(0,1)$, then $P[X^2+Y^2\\leq 1] = \\pi/4$ (see [\"Monte Carlo method\" on Wikipedia](https://en.wikipedia.org/wiki/Monte_Carlo_method)). The following code uses this approach:"
"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:"