diff --git a/module2/exo1/toy_notebook_en.ipynb b/module2/exo1/toy_notebook_en.ipynb index df81e941eaee06f1d96fa0eb2fb31a02a4def4b1..c7406a9f0bc38536b0bc3a8d6755dbdeb61c2767 100644 --- a/module2/exo1/toy_notebook_en.ipynb +++ b/module2/exo1/toy_notebook_en.ipynb @@ -66,7 +66,7 @@ "metadata": {}, "source": [ "## Using a surface fraction argument\n", - "A method that is easier to understand and does not make use of the sin function is based on the fact that if $X \\sim U(0,1)$ $Y \\sim U(0,1)$, then $P[X^2+Y^2\\leq 1] = \\pi/4$ (see [\"Monte Carlo method\" on Wikipedia](https://en.wikipedia.org/wiki/Monte_Carlo_method)). The following code uses this approach:" + "A method that is easier to understand and does not make use of the sin function is based on the fact that if $X\\sim U(0,1)$ and $Y\\sim U(0,1)$, then $P[X^2+Y^2\\leq 1] = \\pi/4$ (see [\"Monte Carlo method\" on Wikipedia](https://en.wikipedia.org/wiki/Monte_Carlo_method)). The following code uses this approach:" ] }, { @@ -88,15 +88,17 @@ } ], "source": [ - "%matplotlib inline\n", + "%matplotlib inline \n", "import matplotlib.pyplot as plt\n", "\n", "np.random.seed(seed=42)\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", "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",