From 9ec3a4c0651ac9f69212c2d25835e6956610359d Mon Sep 17 00:00:00 2001 From: b4be7b445b878ad4e31ba006a9f5a959 Date: Mon, 23 Mar 2020 02:16:53 +0000 Subject: [PATCH] DONE somepart of ittttttttttttttt!!! --- module2/exo1/toy_notebook_fr.ipynb | 50 +++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/module2/exo1/toy_notebook_fr.ipynb b/module2/exo1/toy_notebook_fr.ipynb index b34edd3..56e4aee 100644 --- a/module2/exo1/toy_notebook_fr.ipynb +++ b/module2/exo1/toy_notebook_fr.ipynb @@ -14,40 +14,66 @@ "

March 28, 2019

" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 1. A propos du calcul de $\\pi$\n", + "\n", + "### 1.1. En demandant à la lib maths \n", + "Mon ordinateur m'indique que $\\pi$ vaut *approximativement*\n" + ] + }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1\n" + "3.141592653589793\n" ] } ], "source": [ - "x=1\n", - "print(x)" + "from math import *\n", + "print(pi)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 1.2. En utilisant la méthode des aiguilles de Buffon \n", + "\n", + "Mais calculé avec la **méthode** des [aiguilles de Buffon](http://fr.wikipedia.org/wiki/Aiguille_de_Buffon), on obtiendrait comme **approximation** :\n" ] }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 9, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "[1] 1\n" - ] + "data": { + "text/plain": [ + "3.128911138923655" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "x=1\n", - "print(x)" + "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)\n" ] }, { -- 2.18.1