second essai

parent 00c29591
......@@ -2,14 +2,21 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"hideCode": false,
"hidePrompt": false
},
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"hideCode": false,
"hidePrompt": false
},
"source": [
"# À propos du calcul de $\\pi$\n",
"\n",
"## En demandant à la lib maths\n",
"Mon ordinateur m'indique que $\\pi$ vaut *approximativement*"
]
......@@ -17,7 +24,10 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"metadata": {
"hideCode": false,
"hidePrompt": false
},
"outputs": [
{
"name": "stdout",
......@@ -34,16 +44,22 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"hideCode": false,
"hidePrompt": false
},
"source": [
"## En utilisation la méthode des aiguilles de Buffon\n",
"Mais calculé avec la méthode des aiguilles de Buffon, on obtiendrait comme **approxmiation** :"
"Mais calculé avec la __méthode__ des [aiguilles de Buffon](https://fr.wikipedia.org/wiki/Aiguille_de_Buffon), on obtiendrait comme __approximation__ :"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"metadata": {
"hideCode": false,
"hidePrompt": false
},
"outputs": [
{
"data": {
......@@ -67,16 +83,22 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"hideCode": false,
"hidePrompt": false
},
"source": [
"## Avec un argument \"fréquentiel\" de surface\n",
"Sinon, une méthode plus simple à comprendre et ne faisant pas intervenir d'appel à la fonction sinus se base sur le fait que $X \\sim \\mathcal{U}(0,1)$ et $Y \\sim \\mathcal{U}(0,1)$ alors $\\mathcal{P}[X^2 + Y^2 \\leq 1] = \\pi/4$ (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)). Le code suivant illustre ce fait :"
"Sinon, une méthode plus simple à comprendre et ne faisant pas intervenir d'appel à la fonction sinus se base sur le fait que si $X\\sim U(0,1)$ et $Y\\sim U(0,1)$ alors $P[X^2+Y^2\\leq 1] = \\pi/4$ (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)). Le code suivant illustre ce fait :"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"metadata": {
"hideCode": false,
"hidePrompt": false
},
"outputs": [
{
"data": {
......@@ -93,15 +115,18 @@
],
"source": [
"%matplotlib inline\n",
"\n",
"import matplotlib.pyplot as plt\n",
"np.random.seed(seed=42)\n",
"\n",
"N = 1000\n",
"x = np.random.uniform(size=N, low=0, high=1)\n",
"y = np.random.uniform(size=N, low=0, high=1)\n",
"\n",
"accept = (x*x+y*y) <= 1\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[reject], y[reject], c='r', alpha=0.2, edgecolor=None)\n",
"ax.set_aspect('equal')"
......@@ -109,7 +134,10 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"hideCode": false,
"hidePrompt": false
},
"source": [
"Il est alors aisé d'obtenir une approximation (pas terrible) de $\\pi$ en comptant combien de fois, en moyenne, $X^2 + Y^2$ est inférieur à 1 :"
]
......@@ -117,7 +145,10 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"metadata": {
"hideCode": false,
"hidePrompt": false
},
"outputs": [
{
"data": {
......@@ -136,6 +167,7 @@
}
],
"metadata": {
"hide_code_all_hidden": false,
"kernelspec": {
"display_name": "Python 3",
"language": "python",
......
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