Pi estimate- Added Notes

parent f03f7cbe
......@@ -4,23 +4,17 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# À propos de pi"
"### Estimating π\n",
"\n",
"I tried to compute pi using Buffon’s Needle method with random numbers to estimate the value of π. \n",
"The result is close to 3.14, showing how randomness can be used in simulations."
]
},
{
"cell_type": "code",
"execution_count": 1,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"from random import random \n",
"N=10000\n",
"val=sum(\n",
"1 for _ in range(N)\n",
" if random()**2 + random()**2 <= 1\n",
")\n",
"\n",
"pi_estimate = 4 * val / N"
"# About Pi"
]
},
{
......@@ -34,6 +28,22 @@
"Donc : $\\pi \\approx 4 \\times \\frac{\\text{points dans le cercle}}{\\text{points totaux}}$\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from random import random \n",
"N=10000\n",
"val=sum(\n",
"1 for _ in range(N)\n",
" if random()**2 + random()**2 <= 1\n",
")\n",
"\n",
"pi_estimate = 4 * val / N"
]
},
{
"cell_type": "code",
"execution_count": 8,
......
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