diff --git a/module2/exo1/toy_notebook_en.ipynb b/module2/exo1/toy_notebook_en.ipynb index 4076e2cc49c978ea97075d5cb2236f570b0bb4bf..7f8a39273c428348965d6428b87f5b79945bad0a 100644 --- a/module2/exo1/toy_notebook_en.ipynb +++ b/module2/exo1/toy_notebook_en.ipynb @@ -1,31 +1,51 @@ { "cells": [ { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ "# On the computation of $\\pi$\n" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ "## Asking the maths library\n", "My computer tells me that $\\pi$ is approximately" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "from math import *\n", "print(pi)" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Buffon's needle\n", + "Applying the method of [Buffon's needle](https://en.wikipedia.org/wiki/Buffon%27s_needle_problem), we get the **approximation**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "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": {