From 16db9cf60b2a84b7b4948e63bc2f072857c8f72f Mon Sep 17 00:00:00 2001 From: 7b6ab3e907fcca64ce4257f26cd31e57 <7b6ab3e907fcca64ce4257f26cd31e57@app-learninglab.inria.fr> Date: Wed, 5 Jan 2022 10:12:28 +0000 Subject: [PATCH] =?UTF-8?q?=C3=89crire=20le=20code=20de=20la=20m=C3=A9thod?= =?UTF-8?q?e=20de=20Buffon=20qui=20affiche=203.1289111389236548=20pour=20P?= =?UTF-8?q?ython,=203.14327=20pour=20R?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module2/exo1/toy_notebook_fr.ipynb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/module2/exo1/toy_notebook_fr.ipynb b/module2/exo1/toy_notebook_fr.ipynb index 6086b0f..3a6fe43 100644 --- a/module2/exo1/toy_notebook_fr.ipynb +++ b/module2/exo1/toy_notebook_fr.ipynb @@ -40,6 +40,31 @@ "## En utilisant la méthode des aiguilles de Buffon\n", "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": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3.128911138923655" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import numpy as np\n", + "np.random.seed(seed=42)\n", + "N = 10000\n", + "x = np.random.uniform(size=N, low=0, high=1)\n", + "theta = np.random.uniform(size=N, low=0, high=pi/2)\n", + "2/(sum((x+np.sin(theta))>1)/N)" + ] } ], "metadata": { -- 2.18.1