diff --git a/module2/exo1/toy_notebook_en.ipynb b/module2/exo1/toy_notebook_en.ipynb index 0bbbe371b01e359e381e43239412d77bf53fb1fb..6d10d410d6b9cd0a0eece98656da3256993de6d5 100644 --- a/module2/exo1/toy_notebook_en.ipynb +++ b/module2/exo1/toy_notebook_en.ipynb @@ -1,5 +1,77 @@ { - "cells": [], + "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",