From 92f53900d28124aede86e92eab58faefd086e5bd Mon Sep 17 00:00:00 2001 From: d67f1d289df81656bf4e76b9db13fedf Date: Sun, 13 Nov 2022 22:33:51 +0000 Subject: [PATCH] Code aiguilles de Buffon --- 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 647bab8..820ac41 100644 --- a/module2/exo1/toy_notebook_fr.ipynb +++ b/module2/exo1/toy_notebook_fr.ipynb @@ -36,6 +36,31 @@ "Mais calculé avec la __méthode__ des [aiguilles de Buffon](https://fr.wikipedia.org/wiki/Aiguille_de_Buffon), on obtiendrait comme __approximation__ :\n" ] }, + { + "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)" + ] + }, { "cell_type": "code", "execution_count": null, -- 2.18.1