no commit message

parent 2de543b1
......@@ -6,20 +6,21 @@
"metadata": {},
"outputs": [],
"source": [
"import random\n",
"import math\n",
"import matplotlib.pyplot as plt\n",
"\n",
"def buffon_needle(n_drops=100000):\n",
" hits = 0\n",
" for _ in range(n_drops):\n",
" y = random.random()\n",
" theta = random.uniform(0, math.pi / 2)\n",
" if y <= (math.sin(theta) / 2):\n",
" hits += 1\n",
" return (2 * n_drops) / hits\n",
"# Exemple : afficher la convergence de l'estimation de π\n",
"import numpy as np\n",
"\n",
"pi_est = buffon_needle()\n",
"print(f\"Estimation de π par la méthode de Buffon : {pi_est}\")\n"
"n_values = np.arange(1000, 20000, 1000)\n",
"pi_estimations = [buffon_needle(n) for n in n_values]\n",
"\n",
"plt.plot(n_values, pi_estimations)\n",
"plt.axhline(y=math.pi, color='r', linestyle='--', label='π réel')\n",
"plt.xlabel(\"Nombre d'expériences\")\n",
"plt.ylabel(\"Estimation de π\")\n",
"plt.legend()\n",
"plt.title(\"Convergence de la méthode de Buffon\")\n",
"plt.show()\n"
]
}
],
......
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