{ "cells": ["cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# À propos de pi" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Some mathematical formulas:\n", "$\\pi = \\frac{C}{D}$\n", "$$ \\pi \\approx 3.14 $$" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import math\n", "print(math.pi)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Learn more here: [Aiguilles de Buffon](https://fr.wikipedia.org/wiki/Aiguille_de_Buffon)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import random\n", "import math\n\n", "def buffon_needle(n):\n", " count = 0\n", " for _ in range(n):\n", " x = random.uniform(0, 1)\n", " theta = random.uniform(0, math.pi / 2)\n", " if x <= math.sin(theta):\n", " count += 1\n", " return (2 * n) / count\n\n", "print(buffon_needle(100000))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import numpy as np\n\n", "x = np.linspace(0, 2 * np.pi, 100)\n", "y = np.sin(x)\n\n", "plt.plot(x, y)\n", "plt.title(\"Sine Wave\")\n", "plt.xlabel(\"x\")\n", "plt.ylabel(\"sin(x)\")\n", "plt.grid(True)\n", "plt.show()" ] } ] ], "metadata": { "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.3" } }, "nbformat": 4, "nbformat_minor": 2 }