{ "cells": [ { "cell_type": "markdown", "metadata": { "hideCode": false, "hidePrompt": false }, "source": [ "# 1. A propos du calcul de $\\pi$" ] }, { "cell_type": "markdown", "metadata": { "hideCode": false, "hidePrompt": false }, "source": [ "\n", "## 1. En demandant à la lib maths" ] }, { "cell_type": "markdown", "metadata": { "hideCode": false, "hidePrompt": false }, "source": [ "Mon ordinateur m'indique que $\\pi$ vaut *approximativement*" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "hideCode": false, "hidePrompt": false }, "outputs": [], "source": [ "from math import *\n", "print(pi)" ] }, { "cell_type": "markdown", "metadata": { "hideCode": false, "hidePrompt": false }, "source": [ "## 2. En utilisant la méthode des aiguilles de Buffon" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Mais calculé avec la **méthode** des [aiguilles de Buffon](https://fr.wikipedia.org/wiki/Aiguille_de_Buffon), on obtiendrait comme **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)" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "Caractères spéciaux : https://csrgxtu.github.io/2015/03/20/Writing-Mathematic-Fomulars-in-Markdown/" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "hide_code_all_hidden": false, "kernelspec": { "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, "nbformat_minor": 2 }