diff --git a/module2/exo1/toy_notebook_fr.ipynb b/module2/exo1/toy_notebook_fr.ipynb index a16f597fe40de76c7e7e13406af5c17308ad7ef4..54c5d55bab03d724cf23d11b818e62eedcadf764 100644 --- a/module2/exo1/toy_notebook_fr.ipynb +++ b/module2/exo1/toy_notebook_fr.ipynb @@ -17,8 +17,10 @@ }, { "cell_type": "code", - "execution_count": 12, - "metadata": {}, + "execution_count": 14, + "metadata": { + "scrolled": true + }, "outputs": [ { "name": "stdout", @@ -43,7 +45,40 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3.128911138923655" + ] + }, + "execution_count": 17, + "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": "markdown", + "metadata": {}, + "source": [ + "## Avec un argument \"frésuentiel\" 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 si $X \\sim \\mathcal{U}(0,1)$ et $Y \\sim \\mathcal{U}(0,1)$ alors $P\\left[X^2 + Y^2 \\leq 1\\right] = \\pi/4$\n" + ] + }, + { + "cell_type": "code", + "execution_count": 20, "metadata": {}, "outputs": [ { @@ -68,13 +103,14 @@ "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", "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')\n" + "ax.set_aspect('equal')" ] }, { @@ -86,7 +122,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 21, "metadata": {}, "outputs": [ { @@ -95,7 +131,7 @@ "3.112" ] }, - "execution_count": 9, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -103,13 +139,6 @@ "source": [ "4*np.mean(accept)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": {