Final

parent e4ceab5a
...@@ -4,14 +4,14 @@ ...@@ -4,14 +4,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
" # toy_notebook_fr" "# toy_notebook_fr"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
" ## March 28, 2019" "## March 28, 2019"
] ]
}, },
{ {
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Mais calculé avec la __méthode__ des [aiguilles de Buffon](https://fr.wikipedia.org/wiki/Aiguille_de_Buffon) " "Mais calculé avec la __méthode__ des [aiguilles de Buffon](https://fr.wikipedia.org/wiki/Aiguille_de_Buffon), on obtiendrait comme **approximation** :"
] ]
}, },
{ {
...@@ -104,7 +104,7 @@ ...@@ -104,7 +104,7 @@
"metadata": {}, "metadata": {},
"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$n^2$+Y$n^2$ $\\le$1] = π/4 \n", "sinus se base sur le fait que si X ∼ U(0, 1) et Y ∼ U(0, 1) alors P[$X^2$+$Y^2$ $\\le$1] = π/4 \n",
"(voir [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). \n", "(voir [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). \n",
"Le code suivant illustre ce fait :" "Le code suivant illustre ce fait :"
] ]
...@@ -130,6 +130,7 @@ ...@@ -130,6 +130,7 @@
"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",
...@@ -137,6 +138,7 @@ ...@@ -137,6 +138,7 @@
"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",
...@@ -147,7 +149,7 @@ ...@@ -147,7 +149,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Il est alors aisé d’obtenir une approximation (pas terrible) de π en comptant combien de fois, en moyenne, X$n^2$+Y$n^2$ est inférieur à 1 :" " Il est alors aisé d’obtenir une approximation (pas terrible) de π en comptant combien de fois, en moyenne, X$n^2$+Y$n^2$ est inférieur à 1 :"
] ]
}, },
{ {
......
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