From c3bcf2a59c4674503167db30304e6eb971c393df Mon Sep 17 00:00:00 2001 From: 7db3512460936f19a53c773a40a4fd70 <7db3512460936f19a53c773a40a4fd70@app-learninglab.inria.fr> Date: Sun, 31 Jan 2021 23:20:30 +0000 Subject: [PATCH] kk --- module2/exo1/toy_notebook_fr.ipynb | 69 ++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 14 deletions(-) diff --git a/module2/exo1/toy_notebook_fr.ipynb b/module2/exo1/toy_notebook_fr.ipynb index 40047d1..e6647cb 100644 --- a/module2/exo1/toy_notebook_fr.ipynb +++ b/module2/exo1/toy_notebook_fr.ipynb @@ -1,8 +1,23 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# À propos du calcul de $\\pi$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## En demandant à la lib maths\n", + "Mon ordinateur m'indique que $\\pi$ vaut *approximativement*" + ] + }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -21,7 +36,9 @@ { "cell_type": "code", "execution_count": 4, - "metadata": {}, + "metadata": { + "scrolled": false + }, "outputs": [ { "data": { @@ -43,6 +60,14 @@ "2/(sum((x+np.sin(theta))>1)/N)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Avec un argument \"fréquentiel\" 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 U(0,1)$ et $Y\\sim U(0,1)$ alors $P[X^2+Y^2\\leq 1] = \\pi/4$ (voir [méthode de Monte Carlo sur Wikipedia](https://fr.wikipedia.org/wiki/M%C3%A9thode_de_Monte-Carlo#D%C3%A9termination_de_la_valeur_de_%CF%80)). Le code suivant illustre ce fait :" + ] + }, { "cell_type": "code", "execution_count": 5, @@ -79,6 +104,34 @@ "ax.set_aspect('equal')" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Il est alors aisé d'obtenir une approximation (pas terrible) de $\\pi$ en comptant combien de fois, en moyenne, $X^2 + Y^2$ est inférieur à 1 :" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'accept' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;36m4\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmean\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0maccept\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mNameError\u001b[0m: name 'accept' is not defined" + ] + } + ], + "source": [ + "4*np.mean(accept)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -92,18 +145,6 @@ "display_name": "Python 3", "language": "python", "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.4" } }, "nbformat": 4, -- 2.18.1