Refaire mon toy_notebook

parent 5d17b9ac
...@@ -2,56 +2,50 @@ ...@@ -2,56 +2,50 @@
"cells": [ "cells": [
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"hideCode": false,
"hidePrompt": false
},
"source": [ "source": [
"\n", "<div align=\"center\"> Mon_toy_notebook_fr</div>"
"# toy_notebook_fr\n",
"# Martha HENRI\n",
"# 05/09/2023\n",
"\n",
"\n"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"hideCode": false,
"hidePrompt": false
},
"source": [ "source": [
"# 1. À propos du calcul de $\pi$" "<div align=\"center\">Martha HENRI</div>"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"hideCode": false,
"hidePrompt": false
},
"source": [ "source": [
"**1.1 En demandant à la lib maths**" "<div align=\"center\">19/09/2023</div>\n"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"hideCode": false, "source": [
"hidePrompt": false "## 1 A propos du calcul de $\\pi$"
}, ]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1.1 En demandant à la lib maths"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [ "source": [
"Mon ordinateur m’indique que $\pi$ vaut *approximativement*" "Mon ordinateur m'indique que $\\pi$ vaut *aproximativement*"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": { "metadata": {},
"hideCode": false,
"hidePrompt": false
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
...@@ -68,31 +62,22 @@ ...@@ -68,31 +62,22 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"hideCode": false,
"hidePrompt": false
},
"source": [ "source": [
"**1.2 En utilisant la méthode des aiguilles de Buffon**" "## 1.2 En utilisant la méthode des aiguilles de Buffon"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"hideCode": false,
"hidePrompt": false
},
"source": [ "source": [
"Mais calculé avec la **méthode** des [aiguilles de Buffon](https://fr.wikipedia.org/wiki/Aiguille_de_Buffon), on obtiendrait comme __approximation__ :" "Mais calculé avec la **méthode** des [aiguilles de Buffon](https://fr.wikipedia.org/wiki/Aiguille_de_Buffon), on obtiendrait comme __aproximation__ :\n"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 2,
"metadata": { "metadata": {},
"hideCode": false,
"hidePrompt": false
},
"outputs": [ "outputs": [
{ {
"data": { "data": {
...@@ -116,33 +101,24 @@ ...@@ -116,33 +101,24 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"hideCode": false,
"hidePrompt": false
},
"source": [ "source": [
"**1.3 Avec un argument \"fréquentiel\" de surface**" "## 1.3 Avec un argument \"frequentiel\" de surface"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"hideCode": false,
"hidePrompt": false
},
"source": [ "source": [
"Sinon, une méthode plus simple à comprendre et ne faisant pas intervenir d’appel à la fonction\n", "Sinon, une méthode plus simple à comprendre et ne faisant pas intervenir d’appel à la fonction\n",
"sinus se base sur le fait que si X ∼ U(0, 1) et Y ∼ U(0, 1) alors P[X<sup>2</sup> + Y<sup>2</sup> ≤ 1] = $\pi$/4 (voir\n", "sinus se base sur le fait que si X ~ U(0, 1) et Y ~ U(0, 1) alors P[X<sup>2</sup> + Y<sup>2</sup> <= 1] = $\\pi$/4 (voir\n",
"[méthode de Monte Carlo sur Wikipedia](https://fr.wikipedia.org/wiki/M%C3%A9thode_de_Monte-Carlo#D%C3%A9termination_de_la_valeur_de_%CF%80)). Le code suivant illustre ce fait :" "[méthode de Monte Carlo sur Wikipedia](https://fr.wikipedia.org/wiki/M%C3%A9thode_de_Monte-Carlo)). Le code suivant illustre ce fait :"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 3,
"metadata": { "metadata": {},
"hideCode": false,
"hidePrompt": false
},
"outputs": [ "outputs": [
{ {
"data": { "data": {
...@@ -160,38 +136,32 @@ ...@@ -160,38 +136,32 @@
"source": [ "source": [
"%matplotlib inline\n", "%matplotlib inline\n",
"import matplotlib.pyplot as plt\n", "import matplotlib.pyplot as plt\n",
"\n",
"np.random.seed(seed=42)\n", "np.random.seed(seed=42)\n",
"N = 1000\n", "N = 1000\n",
"x = np.random.uniform(size=N, low=0, high=1)\n", "x = np.random.uniform(size=N, low=0, high=1)\n",
"y = np.random.uniform(size=N, low=0, high=1)\n", "y = np.random.uniform(size=N, low=0, high=1)\n",
"1\n",
"accept = (x*x+y*y) <= 1\n", "accept = (x*x+y*y) <= 1\n",
"reject = np.logical_not(accept)\n", "reject = np.logical_not(accept)\n",
"\n",
"fig, ax = plt.subplots(1)\n", "fig, ax = plt.subplots(1)\n",
"ax.scatter(x[accept], y[accept], c='b', alpha=0.2, edgecolor=None)\n", "ax.scatter(x[accept], y[accept], c='b', alpha=0.2, edgecolor=None)\n",
"ax.scatter(x[reject], y[reject], c='r', alpha=0.2, edgecolor=None)\n", "ax.scatter(x[reject], y[reject], c='r', alpha=0.2, edgecolor=None)\n",
"ax.set_aspect('equal')\n", "ax.set_aspect('equal')"
"\n"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": { "metadata": {},
"hideCode": false,
"hidePrompt": false
},
"source": [ "source": [
"Il est alors aisé d’obtenir une approximation (pas terrible) de $\pi$ en comptant combien de fois,\n", "Il est alors aisé d’obtenir une approximation (pas terrible) de $\\pi$ en comptant combien de fois,\n",
"en moyenne, X<sup>2</sup> + Y<sup>2</sup> est inférieur à 1 :" "en moyenne, X<sup>2</sup> + Y<sup>2</sup> est inférieur à 1 :"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 4,
"metadata": { "metadata": {},
"hideCode": false,
"hidePrompt": false
},
"outputs": [ "outputs": [
{ {
"data": { "data": {
...@@ -207,21 +177,9 @@ ...@@ -207,21 +177,9 @@
"source": [ "source": [
"4*np.mean(accept)" "4*np.mean(accept)"
] ]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"hideCode": false,
"hidePrompt": false
},
"outputs": [],
"source": []
} }
], ],
"metadata": { "metadata": {
"celltoolbar": "Aucun(e)",
"hide_code_all_hidden": true,
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python 3",
"language": "python", "language": "python",
...@@ -241,5 +199,5 @@ ...@@ -241,5 +199,5 @@
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 2 "nbformat_minor": 4
} }
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