Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mooc-rr
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
f50a28a8c82bf67ad820bc82fe37aad2
mooc-rr
Commits
fb534491
Commit
fb534491
authored
Jul 04, 2025
by
f50a28a8c82bf67ad820bc82fe37aad2
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update toy_notebook_fr.ipynb
parent
bae6a1f4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
13 deletions
+79
-13
toy_notebook_fr.ipynb
module2/exo1/toy_notebook_fr.ipynb
+79
-13
No files found.
module2/exo1/toy_notebook_fr.ipynb
View file @
fb534491
`{
{
"cells": [],
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# À propos de π\n",
"\n",
"Dans ce mini-notebook, nous rappelons deux représentations classiques de π :\n",
"\n",
"$$ \\pi = \\frac{C}{D} $$ \n",
"$$ \\displaystyle \\pi = 4 \\sum_{k=0}^{\\infty} \\frac{(-1)^k}{2k+1} . $$\n",
"\n",
"La célèbre expérience des [aiguilles de Buffon](https://fr.wikipedia.org/wiki/Aiguille_de_Buffon) permet aussi d’estimer π de manière probabiliste."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import math\n",
"math.pi"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import random, math\n",
"\n",
"random.seed(42) # pour reproduire la même estimation\n",
"N = 100_000 # nombre de lancers\n",
"l, d = 1.0, 1.0 # longueur de l’aiguille et espacement des lignes\n",
"\n",
"cross = 0\n",
"for _ in range(N):\n",
" x = random.uniform(0, d/2) # distance centre-ligne la plus proche\n",
" theta = random.uniform(0, math.pi/2) # angle avec la verticale\n",
" if x <= (l/2) * math.sin(theta):\n",
" cross += 1\n",
"\n",
"pi_est = (2 * l * N) / (cross * d)\n",
"pi_est"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"def buffon_once(n):\n",
" \"\"\"Une estimation de π par Buffon sur n lancers\"\"\"\n",
" crosses = sum(\n",
" random.uniform(0, d/2) <= (l/2) * math.sin(random.uniform(0, math.pi/2))\n",
" for _ in range(n)\n",
" )\n",
" return (2 * l * n) / (crosses * d)\n",
"\n",
"random.seed(0)\n",
"ests = [buffon_once(2_000) for _ in range(1_000)]\n",
"\n",
"plt.hist(ests, bins=30)\n",
"plt.axvline(math.pi, linestyle='--')\n",
"plt.title(\"Distribution des estimations de π (méthode de Buffon)\")\n",
"plt.xlabel(\"π estimé\")\n",
"plt.ylabel(\"Fréquence\")\n",
"plt.show()"
]
}
],
"metadata": {
"metadata": {
"kernelspec": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3",
...
@@ -7,19 +82,10 @@
...
@@ -7,19 +82,10 @@
"name": "python3"
"name": "python3"
},
},
"language_info": {
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"name": "python",
"nbconvert_exporter": "python",
"version": "3.10"
"pygments_lexer": "ipython3",
"version": "3.6.3"
}
}
},
},
"nbformat": 4,
"nbformat": 4,
"nbformat_minor":
2
"nbformat_minor":
5
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment