{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapitre 15 : Energie potentielle et énergie mécanique\n",
    "## Activité 6 : Distance de freinage d'un véhicule  \n",
    "Correction"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from math import asin, cos, sin"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "g = 9.81                  # intensité de la pesanteur terrestre en N/kg\n",
    "m = 1200                  # masse de la voiture en kg\n",
    "z_0 = 100                 # altitude au debut du freinage en m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "v_0 = float(input('Entrer la vitesse initiale en km/h : v_0='))\n",
    "\n",
    "pente = float(input('Entrer la pente en % : pente='))\n",
    "\n",
    "mu = float(input('Entrer le coefficient de frottement : mu='))\n",
    "\n",
    "alpha = asin(pente/100)      # angle de la pente en radian"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "d = np.linspace(0,150,151)   # definition du domaine des abcisses"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def Em(d):                   # definition de la fonction à représenter\n",
    "    return 0.5*m*(v_0/3.6)**2+m*g*z_0-mu*m*g*d*cos(alpha)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def Epp(d):                  # definition de la fonction à représenter\n",
    "    return m*g*(z_0-d*sin(alpha))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def Ec(d):                   # definition de la fonction à représenter\n",
    "    return Em(d)-Epp(d)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plt.title('Energies en fonction de d') # titre des courbes\n",
    "plt.xlim(0,max(d))\n",
    "plt.xlabel('d (en m)')                 # legende axe des abcisses\n",
    "plt.ylabel('Energie (en kJ)')          # legende axe des ordonnées\n",
    "\n",
    "plt.plot(d,Em(d)/1000,'r',label='Em')  # graphique des points (d,Em(d)) en rouge\n",
    "plt.plot(d,Epp(d)/1000,'b',label='Epp')# graphique des points (d,Epp(d)) en bleu\n",
    "plt.plot(d,Ec(d)/1000,'g',label='Ec')  # graphique des points (d,Ec(d)) en vert\n",
    "\n",
    "plt.legend()                           # ecrit les labels avec les couleurs\n",
    "plt.grid()                             # insere une grille\n",
    "plt.show()                             # affiche les graphiques"
   ]
  }
 ],
 "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.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
