{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sympy import *\n",
    "init_printing()\n",
    "import matplotlib.pyplot as plt\n",
    "import scipy.integrate as integrate\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Principle of Least Action\n",
    "\n",
    "based on Chapter 14 of Eriksson, Kenneth, Donald Estep, and Claes Johnson. 2004. *Applied Mathematics: Body and Soul*. Volume 2. Berlin, Heidelberg: Springer Berlin Heidelberg. <https://doi.org/10.1007/978-3-662-05798-8>.\n",
    "\n",
    "The principle of least action states that a system's trajectory $u(t)$ under the effect of conservative forces, over an interval of time $[t_1, t_2]$ is such that the following integral, called the action integral, is stationary:\n",
    "$$\n",
    "I(u)=\\int_{t_1}^{t_2} T(\\dot{u}(t)) - V(u(t)) dt\n",
    "$$\n",
    "where $T(\\dot{u}(t))$ is the kinetic energy and $V(u(t))$ is the potential energy."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Example 1.** Consider a ball that gets thrown into the air, under the influence of gravity. \n",
    "\n",
    "Its trajectory $u: [t_1, t_2] \\to \\mathcal{R}$ is a parabola between times $t_1$ and $t_2$, with $u(t_1) = u_1$ denoting the initial position, and $u(t_2) = u_2$ denoting the final position of the ball.\n",
    "The kinetic energy of the ball is  $T(\\dot{u}(t)) = \\frac{1}{2}m\\dot{u}(t)^2$ and the potential energy is $V(u(t)) = mgu(t)$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHcAAAAYCAYAAADAm2IFAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAFDUlEQVRoBe2ajVUcNxCAOR4FAO7A7gDHHUAHOKnAdgf4pQIedOCkAgd3YKcC23RgOjC+DvD3bTR6WiFuj7uFM0fmPbHSaDSaH81odo/J1dXVxmODyWRygs7btKe0C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S34LT1rfqa1GtfRYoCMT4ZILH6Zx5Cc6tY7uEnyuOo8wILOLEFn747hXCMpDF9u4F15HqewnKj6fnJsZQ6dXq7vTie0dSaQro7Q3j2GYw+hCUNU2690OCSnMp+XEiZd3pc4+nXkOr29tHMxtinjMm0q00iLXvSvOkTCQXNF82tUCSfgLJwyMHatkV/eVV0UMpedRD9SdI7QxMSo7w4BNPZNmT0jJbpVP4bkVIdSX+lfNHSJLBn6dONR/hMjGfBPOEfxZCV3XAsBnSW80Vg6zcOgAt5nU5p9T+K1X2qgM0otHj7TIjX5TTtX1OCDnwemcz7z9Z0l2WiAXF1mYJ/b3rnqOlNOeKuDTtZ2vv5lXZjT2X6Xfw4+H17wvoIejOJcGK0EUMJ07J2Uq8VVCIIcCzl3DFnZW6f7ASdnr+Tcnc0xNrgPHgi8V+7D2FNrJEdqLqfvu69hc0Td8+ZGfs6E2MWD9gFnTx9E5CJwfH3ZUWiNB+6XiFplWTVgC79MxTWVf59+KM6Nu1aHGrHesXf6Qz78Hzz8BFyIHZlFTB4cAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$\\displaystyle - 0.5 g t^{2} + t v_{0}$"
      ],
      "text/plain": [
       "         2       \n",
       "- 0.5⋅g⋅t  + t⋅v₀"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Needed symbols\n",
    "t, v0, t1, t2, g, m, e = symbols('t, v0, t1, t2, g, m, e')\n",
    "\n",
    "# Symbolic equation for the ball's trajectory\n",
    "a_t = v0*t - 0.5 * g * t**2\n",
    "\n",
    "a_t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 30728 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Defines constant values of a given simbolic expression.\n",
    "def constants(expr):\n",
    "    return expr.subs(v0, 50.0).subs(g, 10.0).subs(m, 1.0)\n",
    "\n",
    "# Kinetic energy\n",
    "def T(u_t):\n",
    "    dot_u = u_t.diff(t)\n",
    "    return 0.5 * m * (dot_u)**2\n",
    "\n",
    "# Potential Energy\n",
    "def V(u_t):\n",
    "    return m * g * u_t\n",
    "\n",
    "ts = np.linspace(0.0, 10.0, 1000)\n",
    "\n",
    "# Computes a trajectory\n",
    "def compute_t(expr):\n",
    "    return [ constants(expr).subs(t, t_val) for t_val in ts]\n",
    "\n",
    "\n",
    "a_t_plot = compute_t(a_t)\n",
    "\n",
    "T_t_plot = compute_t(T(a_t))\n",
    "\n",
    "V_t_plot = compute_t(V(a_t))\n",
    "\n",
    "action_t_plot = compute_t(T(a_t) - V(a_t))\n",
    "\n",
    "plt.figure(1)\n",
    "\n",
    "plt.subplot(2,1,1)\n",
    "\n",
    "plt.plot(ts, a_t_plot, label='height')\n",
    "\n",
    "plt.legend()\n",
    "\n",
    "plt.subplot(2,1,2)\n",
    "\n",
    "plt.plot(ts, T_t_plot, label='kinetic energy')\n",
    "\n",
    "plt.plot(ts, V_t_plot, label='potential energy')\n",
    "\n",
    "plt.plot(ts, action_t_plot, label='T(a_t) - V(a_t)')\n",
    "\n",
    "plt.xlabel('t (s)')\n",
    "\n",
    "plt.legend()\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let us clarify what is meant with requiring that the action integral $I(u)$ is stationary. \n",
    "\n",
    "Consider a possible trajectory  $u: [t_1, t_2] \\to \\mathcal{R}$ and consider its perturbed version $v: [t_1, t_2] \\to \\mathcal{R}$, given by $v(t) = u(t) + \\epsilon w(t)$, or written equivalently, $v(t)=(u + \\epsilon w)(t)$, where $w(t)$ is such that $w(t_1)=w(t_2)=0$, so that $v(t_1) = u(t_1)$ and $v(t_2) = u(t_2)$.\n",
    "\n",
    "Before we proceed, recall the example trajectory of the ball:"
   ]
  },
  {
   "cell_type": "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eRn/DftE+NpMGQ+vjDVRZ0nvlULxNJbP9nL6JBvDdpwl/k/6gnGFouzirWWnJesCdl/h4ffv0tQ/3C+Ts3v6a5DjjPa9lYy1EK/iLgWJm4ajrQfoMJCOOa/UfVXQUC1fpUJB3qKjWSdKM9eIcRY42jAoPc0S+e6OppBLQ7s0UVHzYH9zCjqcFrPzRrfJGfowry6qUt9t/radlqsr4NMW+xvztp8zjkjRgFqCIfXEVXTtSJBmuD5JS34LT1rfqa1GtfRYoCMT4ZILH6Zx5Cc6tY7uEnyuOo8wILOLEFn747hXCMpDF9u4F15HqewnKj6fnJsZQ6dXq7vTie0dSaQro7Q3j2GYw+hCUNU2690OCSnMp+XEiZd3pc4+nXkOr29tHMxtinjMm0q00iLXvSvOkTCQXNF82tUCSfgLJwyMHatkV/eVV0UMpedRD9SdI7QxMSo7w4BNPZNmT0jJbpVP4bkVIdSX+lfNHSJLBn6dONR/hMjGfBPOEfxZCV3XAsBnSW80Vg6zcOgAt5nU5p9T+K1X2qgM0otHj7TIjX5TTtX1OCDnwemcz7z9Z0l2WiAXF1mYJ/b3rnqOlNOeKuDTtZ2vv5lXZjT2X6Xfw4+H17wvoIejOJcGK0EUMJ07J2Uq8VVCIIcCzl3DFnZW6f7ASdnr+Tcnc0xNrgPHgi8V+7D2FNrJEdqLqfvu69hc0Td8+ZGfs6E2MWD9gFnTx9E5CJwfH3ZUWiNB+6XiFplWTVgC79MxTWVf59+KM6Nu1aHGrHesXf6Qz78Hzz8BFyIHZlFTB4cAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$\\displaystyle - 0.5 g t^{2} + t v_{0}$"
      ],
      "text/plain": [
       "         2       \n",
       "- 0.5⋅g⋅t  + t⋅v₀"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_t"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "and here's an example perturbation:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 4144 characters]\n",
      "text/latex": [
       "$\\displaystyle e \\left(25 - \\left(t - 5\\right)^{2}\\right) - 0.5 g t^{2} + t v_{0}$"
      ],
      "text/plain": [
       "  ⎛            2⎞          2       \n",
       "e⋅⎝25 - (t - 5) ⎠ - 0.5⋅g⋅t  + t⋅v₀"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def perturbed(u_t):\n",
    "    w_t = 5**2 - (t-5)**2\n",
    "    return u_t + e*w_t\n",
    "\n",
    "perturbed(a_t)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can pick values for $e$ and plot the perturbed trajectories:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 42812 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "es = np.linspace(-1.0, 1.0, 5)\n",
    "\n",
    "plt.figure(1)\n",
    "for e_val in es:\n",
    "    u_t_e = compute_t(perturbed(a_t).subs(e, e_val)) \n",
    "    plt.plot(ts, u_t_e, label='u_t (e='+str(e_val)+')')\n",
    "    \n",
    "plt.xlabel('t (s)')\n",
    "\n",
    "plt.legend()\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Notice that $w(t)$ can vary arbitrarily in the open interval $(t_1, t_2)$ but is constrained in the boundaries to be 0.\n",
    "Hence all perturbed trajectories of the ball will have the same initial and final values."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For any such perturbation $w(t)$ the integral $I(u)$ is stationary when $u(t)$ satisfies \n",
    "$$\n",
    "\\frac{d}{d\\epsilon}I(u + \\epsilon w) = 0 \\text{ for } \\epsilon = 0 \\qquad \\text{(1)}\n",
    "$$\n",
    "**Remark:** Why can't we simplify $u + \\epsilon w$ to $u$ in the above equation (since $\\epsilon = 0$...)? The reason becomes clear when we apply the limit definition of the derivative, taking into account that $\\epsilon = 0$:\n",
    "$$\n",
    "\\frac{d}{d\\epsilon}I(u + \\epsilon w) = \\lim_{\\Delta \\epsilon \\to 0} \\frac{I(u + \\Delta \\epsilon w) - I(u)}{\\Delta \\epsilon}\n",
    "$$\n",
    "The above expansion makes it clear that  $\\frac{d}{d\\epsilon}I(u) \\neq \\frac{d}{d\\epsilon}I(u + \\epsilon w)$ for $\\epsilon = 0$. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Empirical Evaluation\n",
    "\n",
    "Intuitively, constraint (1) resembles a constraint on a minimum (or maximum) point of a continuous function. Except that in this case, the minimum is a perturbed function (instead of a point).\n",
    "\n",
    "Suppose we want to empirically use constraint (1) to check which one of the following trajectories is the correct one for the ball."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Trajectory 1: $a(t) = \\dot{u}_1 t - \\frac{1}{2} g t^2$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAHcAAAAYCAYAAADAm2IFAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAFDUlEQVRoBe2ajVUcNxCAOR4FAO7A7gDHHUAHOKnAdgf4pQIedOCkAgd3YKcC23RgOjC+DvD3bTR6WiFuj7uFM0fmPbHSaDSaH81odo/J1dXVxmODyWRygs7btKe0C9pb7DDluVYweWzOTY59h946dYPxGY+njJ+vlWdRZnPdFJpDn8OK5pjxHk42itcKHqNzdWDpyEjHJW4tnLy1FlrcQgnS77OKfC+Nv1T4Bz98rJFbOs7i6v+CqrRI3U+Fynfwpjmj4z1Rcl7Ttcas/Qr+He0f1kwZG01vaB8Zf+B5J5Bk3mYP91o/QLGNZRt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D9SdI7QxMSo7w4BNPZNmT0jJbpVP4bkVIdSX+lfNHSJLBn6dONR/hMjGfBPOEfxZCV3XAsBnSW80Vg6zcOgAt5nU5p9T+K1X2qgM0otHj7TIjX5TTtX1OCDnwemcz7z9Z0l2WiAXF1mYJ/b3rnqOlNOeKuDTtZ2vv5lXZjT2X6Xfw4+H17wvoIejOJcGK0EUMJ07J2Uq8VVCIIcCzl3DFnZW6f7ASdnr+Tcnc0xNrgPHgi8V+7D2FNrJEdqLqfvu69hc0Td8+ZGfs6E2MWD9gFnTx9E5CJwfH3ZUWiNB+6XiFplWTVgC79MxTWVf59+KM6Nu1aHGrHesXf6Qz78Hzz8BFyIHZlFTB4cAAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$\\displaystyle - 0.5 g t^{2} + t v_{0}$"
      ],
      "text/plain": [
       "         2       \n",
       "- 0.5⋅g⋅t  + t⋅v₀"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_t"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Trajectory 2: $b(t) = 2 a(t)$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAIEAAAAYCAYAAADdyZ7bAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAFRklEQVRoBe2ajXFUOQyAs0wK2IQOQgfh6CDpgBwVcHQAcxUwSQc5KmBCB3AVBNIB6eDCdpD7Psd64+d9S3b37R/z8IzjP0mWZEmW32Z0f3+/N7QyGo3OkXlMPaLeUt+hhwntIMtoaEaQDeASuT38PcZXNEeMnw/SAhD6yQAFf1nJ/J7xMcZgVBhkGaIReNDlgcc1UM4Nyhj2ByUtwhL2n1UyH+fx12p+MMOhRoLygE0SfyeGpUa21c8J23/sb3jWWz/itTfr5CfvOWafN+vc52e04cFXioZoiStJo1yr7A/b5b9sZohcSYWkSdc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F4Q9hdZjrhCkvHROZ1mnj4k7yateYw6cfV0Hh8hhc/rhH7huqWkjLcVpssS5KB/nmul1kun7xh8I/JI1ypF+E1rFrmiK4hdxqv5D+LYNqERoJxN7m5P8362be5p4DzyaJ3txIl5mX6b2okgWa072shgJO+d+Y1NUKdvzm0fh4GToXIU1JwyQNzKy/sp9cunBOAp0MYCbqK4T3JNY88wCirxqCOzS1KvatfP0U/Z74xDHB8ip6uxAggtJWCEF4DKmsqmdokQ/CxlBFsmEeNw+jSRM1sBAervg7WJhcMtzyGsdZtZEjevraN5yOsYhvPmw9l41BGxiYCZ8P1e8Tkl4gEMBxfuQ5kWvUxtxNRYONH2WNDdOYzNK5Rf71MEfRXMYLIBTx4I4B3pZ+O40MJw99lWQ38D7i/aNPHhu65AAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$\\displaystyle - 1.0 g t^{2} + 2 t v_{0}$"
      ],
      "text/plain": [
       "         2         \n",
       "- 1.0⋅g⋅t  + 2⋅t⋅v₀"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b_t = 2*a_t\n",
    "b_t"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "All we have to do is pick an arbitrary perturbation function $w(t)$ that satisfies the assumptions. For instance, pick \n",
    "$$w(t) = 5^2 - (t-5)^2$$\n",
    "Then, for a range of values $e$ we compute the value $I(u + \\epsilon w)$ and we check if it is constant around $e=0$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Computes the action integral in [0,10]\n",
    "def I(u_t):\n",
    "    integrand = T(u_t) - V(u_t)\n",
    "    integrand_t = constants(integrand)\n",
    "    result, tol = integrate.quad(lambda t_val: integrand_t.subs(t, t_val), 0, 10.0)\n",
    "    return result"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's start with Trajectory 2:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 38888 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Show perturbed trajectories for Trajectory 2\n",
    "plt.figure(1)\n",
    "\n",
    "for e_val in es:\n",
    "    b_t_e = compute_t(perturbed(b_t).subs(e, e_val)) \n",
    "    plt.plot(ts, b_t_e, label='b_t (e=)'+str(e_val))\n",
    "    \n",
    "plt.xlabel('t (s)')\n",
    "\n",
    "plt.legend()\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 14400 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Compute the action integral for each value of e\n",
    "Is = [I(perturbed(b_t).subs(e, e_val)) for e_val in es]\n",
    "\n",
    "plt.figure(1)\n",
    "\n",
    "plt.xlabel('e')\n",
    "\n",
    "plt.plot(es, Is, label='I')\n",
    "\n",
    "plt.legend()\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Clearly, around $e=0$ this plot is not stationary (it's increasing!).\n",
    "\n",
    "Now let's try with trajectory $a(t)$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 42940 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Show perturbed trajectories for Trajectory 1\n",
    "plt.figure(1)\n",
    "\n",
    "for e_val in es:\n",
    "    a_t_e = compute_t(perturbed(a_t).subs(e, e_val)) \n",
    "    plt.plot(ts, a_t_e, label='a_t (e=)'+str(e_val))\n",
    "    \n",
    "plt.xlabel('t (s)')\n",
    "\n",
    "plt.legend()\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 18164 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Compute the action integral for each value of e\n",
    "Is = [I(perturbed(a_t).subs(e, e_val)) for e_val in es]\n",
    "\n",
    "plt.figure(1)\n",
    "\n",
    "plt.xlabel('e')\n",
    "\n",
    "plt.plot(es, Is, label='I')\n",
    "\n",
    "plt.legend()\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The action integral seems to have a minimum at $e=0$, which is promising. Let's increase the resolution and try again:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 18168 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "es = np.linspace(-1.0, 1.0, 100)\n",
    "\n",
    "Is = [I(perturbed(a_t).subs(e, e_val)) for e_val in es]\n",
    "\n",
    "plt.figure(1)\n",
    "\n",
    "plt.xlabel('e')\n",
    "\n",
    "plt.plot(es, Is, label='I')\n",
    "\n",
    "plt.legend()\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Theoretical Derivation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this section, we show how to use calculus to simplify the stationary action integral constraint and apply it to determine which of the trajectories of the bouncing ball above is the correct one.\n",
    "\n",
    "Let $w(t)$ be a given function satisfying $w(t_1) = w( t_2 ) = 0$. Expanding the above constraint gives:\n",
    "$$\n",
    "\\frac{d}{d\\epsilon}I(u + \\epsilon w) = \\frac{d}{d\\epsilon} \\int_{t_1}^{t_2} T(\\frac{d}{dt}(u + \\epsilon w)(t)) - V((u + \\epsilon w)(t)) dt \\\\\n",
    "\\text{expand derivative} = \\frac{d}{d\\epsilon} \\int_{t_1}^{t_2} T(\\dot{u}(t) + \\epsilon \\dot{w}(t)) - V(u(t) + \\epsilon w(t)) dt  \\\\\n",
    "\\text{expand V and T} = \\frac{d}{d\\epsilon} \\int_{t_1}^{t_2} \\frac{1}{2}m(\\dot{u}(t) + \\epsilon \\dot{w}(t))^2 - mg(u(t) + \\epsilon w(t)) dt \\\\\n",
    "\\text{omit (t)} = \\frac{d}{d\\epsilon} \\int_{t_1}^{t_2} \\frac{1}{2}m(\\dot{u} + \\epsilon \\dot{w})^2 - mg(u + \\epsilon w) dt \\\\\n",
    "\\text{factor m} = m \\frac{d}{d\\epsilon} \\int_{t_1}^{t_2} \\frac{1}{2}(\\dot{u} + \\epsilon \\dot{w})^2 - g(u + \\epsilon w) dt \\\\\n",
    "\\text{expand} = m \\frac{d}{d\\epsilon} \\int_{t_1}^{t_2} \\frac{1}{2} \\dot{u}^2 + \\dot{u} \\epsilon \\dot{w} + \\frac{1}{2} \\dot{w}^2 - gu - g\\epsilon w dt \\\\\n",
    "\\text{move der inside} = m \\int_{t_1}^{t_2} \\frac{d}{d\\epsilon}\\frac{1}{2} \\dot{u}^2 + \\frac{d}{d\\epsilon}\\dot{u} \\epsilon \\dot{w} + \\frac{d}{d\\epsilon} \\frac{1}{2} \\dot{w}^2 - \\frac{d}{d\\epsilon} gu - \\frac{d}{d\\epsilon}g\\epsilon w dt \\\\\n",
    "\\text{simplify derivative} = m \\int_{t_1}^{t_2} \\dot{u} \\dot{w} - g w dt \\\\\n",
    "\\text{simplify integral} = m \\left[ \\int_{t_1}^{t_2} \\dot{u} \\dot{w} dt - g \\int_{t_1}^{t_2} w dt \\right] \\\\\n",
    "\\text{1st integral by parts} = m \\left[  [\\dot{u} w]_{t_1}^{t_2} - \\int_{t_1}^{t_2} \\ddot{u} w dt - g \\int_{t_1}^{t_2} w dt \\right] \\\\\n",
    "\\text{apply } w(t1)=w(t2)=0 \\text{ : } = m \\left[ - \\int_{t_1}^{t_2} \\ddot{u} w dt - g \\int_{t_1}^{t_2} w dt \\right] \\\\ \\\\\n",
    "\\text{join integrals and factor w: } =   \\int_{t_1}^{t_2} (m\\ddot{u} + mg) w dt \\\\\n",
    "$$\n",
    "So we get the simplified constraint\n",
    "$$\n",
    "\\int_{t_1}^{t_2} (m\\ddot{u} + mg) w dt = 0\n",
    "$$\n",
    "Since it applies to **any** given $w$, which can vary **arbitrarily** in the open interval $(t_1,t_2)$, the above constraint can only be satisfied if:\n",
    "$$\n",
    "m\\ddot{u} + mg = 0 \\Leftrightarrow m\\ddot{u} = -mg \\qquad (2)\n",
    "$$\n",
    "**Remark:** one can think of $w$ as an adversary that wants to violate the above constraint. It, at any sub_interval of $[t_1, t_2]$, $m\\ddot{u}(t) + mg \\neq 0$ then $w$ could be any non-zero constant, which would violate the constraint.\n",
    "\n",
    "Equation (2) can now be used to check whether $a(t)$ or $b(t)$ is the correct equation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEYAAAASCAYAAADmMahlAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADBUlEQVRYCdWXgXETMRBFzx4XAKSD0EGACrA7gFABpAMyVMCYDhIqYEIHSSoITge4A4g7MO/ptMf54mQuc5dcsjN7klYrafdrtTqN1ut18RhoNBrNseMPvIJfwj+w7ZJyGBKYvhgP3sFX8LO7zIn+wrExxvHwb3g3ZA9dTli8E7HTOvEdXsK7sO3WxPhPKAvAzxhEfYXc9gn8KuQPWva5Exiuk57N1hGD7il80rQDmdF3p7mac3Rpj1l8aJreYIC5Rrqpv+y9p2/no9TFrnwMneLvLfN4PDeIcUbTDDYPSR7jAyJEWUG/YFp37CEsOUZ6A1+g+w29PeofYJO+8iPkZ5TFoMCw/guNgCI6ylb53QoWznh77dVA0HkBOi6Hpe+M/kN0PaZH8KlA2IPMHHhFafNSPSu0Bc6c9tz20MBog3Rbwt4pVSrjP9NOxivHsWV2UhB00Ci4sA4J2ipASZL/m7GDPEVHTV7ZMWEiG+e5s23xkUn7+MfYGhU1Q60a5kHefmesvQpBBsJmOLnUtuyXwKTjFfqUAid9LYvqq17MUUzyIoNcia6NA1oWR6qykkrsnvkjIkGZ4V4n84lgJLCiRKbciKqctQ0JQKWfJOVH/Qqsca1jqKqGBwh1GwKscOx17ox26G7sdAgplW+LagGo/pnUZ3OUaUOSG22PARgjIJymWpHPApNjigTq6djRThFUaZWRkfJLTWZ1H94AsXa8mvrv0XUt85XHb9rbc4BJma8wMW79KUPujti3ULfOyLxVmk8CnxbePkmXeoyvngnIBPXaesh0Tvk0xltC3jxUr63vk2SedVI5UbsrgbJXoqFvSErnyH5RCkK6RinNJ+52c8fVN8d9ybtl23+Kt4ypjkIe7/GYo+et422V5rOPep0ExjyyETHIlNev9Rhjbpkxr3/u+lKMGGz5JAlHPBICcNC3A+O+J7yv+QAhrtm0BG2PlhHavKV6MeFJAAMI/u0uMhjhuIAcbzku0d+p7CXHdLKg3WCPjPlhP4PjjeW7ZuPabTdVO61/hXHioO0F4OUAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$\\displaystyle - 1.0 g m$"
      ],
      "text/plain": [
       "-1.0⋅g⋅m"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m*b_t.diff(t).diff(t) + m*g"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAOCAYAAAAWo42rAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAzklEQVQoFW1SiRGCMBAkGQtgtAPswKcCKYEa7MESLMWhBGkBOtAOEDuA3XDL3Cg3c9lkby+bEMI4jpkihHDHvEd+kXvkA/UOmGUUmrjFsnLrHOsXskh1E11BDBIJwdGh9cIniFoCIbgKybPlEQOjnOFv5FkZZcQFeBbGZ4bVseCOWyup2yuXZlmzqJ29UPMdhUuXWIdy6yNuKEuRTre4vGXdoLpmreZGwhrCk9/K5nzGLrm6j8vn+n3CAdyBmo11Eo7IG75rYdwZeIEo/RQTNRRqzYwqZmYAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$\\displaystyle 0$"
      ],
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m*a_t.diff(t).diff(t) + m*g"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Which shows that $a(t)$ is the correct trajectory."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Exercise\n",
    "\n",
    "Use both the above methods to check which of the following is the correct trajectory for the mass-spring system (there are no external forces acting on the system). \n",
    "Assume that the mass starts at rest in position $1$."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAFEAAAAUCAYAAAD1GtHpAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAD7ElEQVRYCe2ZjU1bQQzHSdQBKN0ANkjSDWADKBM0bABiggo2oN2gsAFhAhQ2SDoBJRuk/5+xj3vvXRIpH0WNasm8O3+d7fP5LqI1nU53thlarda+4jtUnN/XEafsHcvOk+yNkz2S+F4oJwjwRdjfhA+yuyu8X7dt2bwV7ofdtibvCQQJHmzIiQfZPVvFtipv5NWcm/mqCYk0aJHNbQQF3ldcXcW3dBL96N7KRqueI/GuRHsW73qbkzhSkEcK8q131TOxYK5E3UikJxvduqh4nKBf4n38UGf+zbkcoSfiDH35aV1ru11sLp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       "$\\displaystyle m \\sin{\\left(c t \\right)}$"
      ],
      "text/plain": [
       "m⋅sin(c⋅t)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x, m, c = symbols('x, m, c')\n",
    "\n",
    "# Trajectory 1:\n",
    "a_t = m*sin(c*t)\n",
    "a_t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAG0AAAAzCAYAAACdfIbRAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAItklEQVR4Ae2cjVHdOBDHgUkBhFQQ6IBwFYTrIIQKSDqAoYKb0EFCBXekg9BBAh3AVRCgA+7/09MK2fhDtsWz3sztjLA+V/uhXa1kP9YfHx/X/od+Cayvr39Rr+P+nuN7SBfrKaM3UjqV1AfhKe3PQNMHhPpSSfy8Fl8XKXytlNL8al+T4C5TmMvVR/NuC9dtLnxNeMTTg+q/aq6rpva4bmWUJmZwTdti7iRmYEn5Xc3z46Xn8ouxV3EroTQp7IMEdiqmDl5acC34/1T9UqxbPH7TXHfimT20EfDRjQ2lVIr4TdHyr9KBX4lLJ0003GjunWVN3MfzKlgam/M/MyqMRcN+szQQr8x3pNQYmBStNK043CKR4hz7mKZ1wPxLcY1+PveQ4r4r0+gmX8UdC8zj17/5lTcXeX9o4sFBiBYctP+OiL4UH9dROSXLYr0Qrq8a+xS9qkAIXVwSsZ+U2HCJGGejT/MTgm+m0gC9SjdKnOsc3cqj9CsrD3l6XCgtyKBk98gqY3U+rTBVzAGiYciehoK+awzuzYDxf1lh4BOL/eSDk8XQWIOl5EUZ5yKsbH9OmphfqbLKu+ihrxJ0J1tmFz7awOVxHlvfUi3tswh9EJFLDwCQUgRDD9UfNRbvMMQyo+meZz0u9sJDay1VaY55I3LGZ/Kh2rsvrGJosJHC3t/qtKs52C/XilOaCGN1w/zgiA2GMgNBUJLVRP0IQp6B+OL4MhZs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TNm5ZapgCckrZ6mpCKeOF28cAz6LVztDNqIsPhCpUy3GiLwuxFiJbq1ObnJZfLGP4RaPxFs18Khh+Q9nLKErX/Tp8wAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$\\displaystyle \\cos{\\left(t \\sqrt{\\frac{c}{m}} \\right)}$"
      ],
      "text/plain": [
       "   ⎛      ___⎞\n",
       "   ⎜     ╱ c ⎟\n",
       "cos⎜t⋅  ╱  ─ ⎟\n",
       "   ⎝  ╲╱   m ⎠"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Trajectory 2:\n",
    "b_t = cos(sqrt(c/m)*t)\n",
    "b_t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGsAAAAzCAYAAACQYvaWAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAIg0lEQVR4Ae2cjVXdNhTHA4cBKJ2gZAOgG9ANQjMBZIPkMEFPsgFhgoRsEDYgsAF0ggAb0P9P1jW2nvws28JWe3rP0bOtj6v7rSvZsPH09PTqf4hLYGNj46Na3sdb89RK/hupmDZTOy7dD8GpHM5MxxuE+ZJFPG2rXKTw9a9QFoqCGQntMoWpHH00567w3OXAtQ6HeHpU+5nmu17Xj7bilSUmCEO7YupDHzOZ2/eE73tmnFF03gh7FVa0sqSoN+LuVMwcRbl82co/hH42TxaPnzXfvXh2USTGGvE4Vr94nYjeFhF/qxx5y5uVJs1/q3lfzzlpH88lexaL7teFFIWhsJbMCuKVOY9VoglHkcqShRH+yPzmXqc0pQPmni0E+jndRQr7pptoONxqdizonrj92VvaEmT9rkmjyYUMCUWynu2qmDFhXADjrkT3J/UjQXmr8tPXn6k+1QDAeyEcjHnOSPVASlxMEZEnKiykZICL0KW5SaO3Y/Or/iP1ApRJeW/9dE/4pJEM9rBRjzIf7Dnlqv63KiirlkGJYRCruhSRzxalirl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H3wHH2vV9yaJUIdiFk84FjFpfNV7eRfS+HtOhlhZgR4VOc/ailWWQhBCmPnzqdyuRRGRhj7m1+mWxTEI2sq61xneC5aWUjPiBcztu+YIlTS9eZx0BRc2caKN/Z9JD2tjDKcoNgEY4XQKg3me45SQ1hIctKzFMU6Rfg7Fm/thCLA8A9xVGoGQDbc/AAAAABJRU5ErkJggg==\n",
      "text/latex": [
       "$\\displaystyle \\sin{\\left(t \\sqrt{\\frac{m}{c}} \\right)}$"
      ],
      "text/plain": [
       "   ⎛      ___⎞\n",
       "   ⎜     ╱ m ⎟\n",
       "sin⎜t⋅  ╱  ─ ⎟\n",
       "   ⎝  ╲╱   c ⎠"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Trajectory 3:\n",
    "c_t = sin(sqrt(m/c)*t)\n",
    "c_t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGsAAAAzCAYAAACQYvaWAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAIcElEQVR4Ae2cjVEcNxTH4YYCCKkgpgNwOiAdmLgCcAd4qCDjdGC7ghh3YDqwcQeQCgx0QP4/nd6eVqe91e6KWyUTzeh2Vx/vU+9D2oXdp6ennf9LWgK7u7vv1HOR7i3TKvnv5kJa5A6cexyCUz3ZMh2vEOZzVvG0r3qVw9e/QlkoCmYktOscpkqMEc4XgnNXAtYmGOLpUf3vhe9m0zj6qleWmMANvRBTb/uYKdx/JHhfCsNMgvOLsFdhVStLinol7i7FzGmSy+dt/E3gt2bJ4vGD8N2LZ+dFUqzhj1Pts7eJ6H0R8bfqqV95W6VJ+G+F93CbSPt4rtmyCLqfZlIUC4VYstUiXsF5pppMOKpUllYY7o/Mb9txSihdAffWXKDH6S5S2GfdJN3hXjiwonv89ge/0uYg61chHZVcaKFB+4+A6Gvx8T14zrllkV4J1nvNXWW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wr+MCEmWcwh3G8iuMjnYYKHMPkSCwHwh29F4ApW0SI6sdCPqr+IRktoljjUUKsrRLj4bY6EitAoWPgralbcKIU3F47oIu7Bc7PFCOcu1FFlEZFYAO7QpfOFiDTXZddCYIuBwaI6/1FLtcqCfSmMdJdP5UopjHQ9tQ8C3axFPBLTyIA73XPVykJ6RryYsX3HFKGyMW3tg6YAKzVXvJH0vBGvtg9Mgq42wYipFUNkUnzPUasLi0nOehZfxCnc35l4aycUEYR/AKbUd9UWtDS9AAAAAElFTkSuQmCC\n",
      "text/latex": [
       "$\\displaystyle \\sin{\\left(t \\sqrt{\\frac{c}{m}} \\right)}$"
      ],
      "text/plain": [
       "   ⎛      ___⎞\n",
       "   ⎜     ╱ c ⎟\n",
       "sin⎜t⋅  ╱  ─ ⎟\n",
       "   ⎝  ╲╱   m ⎠"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Trajectory 4:\n",
    "d_t = sin(sqrt(c/m)*t)\n",
    "d_t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAOCAYAAAAWo42rAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAzklEQVQoFW1SiRGCMBAkGQtgtAPswKcCKYEa7MESLMWhBGkBOtAOEDuA3XDL3Cg3c9lkby+bEMI4jpkihHDHvEd+kXvkA/UOmGUUmrjFsnLrHOsXskh1E11BDBIJwdGh9cIniFoCIbgKybPlEQOjnOFv5FkZZcQFeBbGZ4bVseCOWyup2yuXZlmzqJ29UPMdhUuXWIdy6yNuKEuRTre4vGXdoLpmreZGwhrCk9/K5nzGLrm6j8vn+n3CAdyBmo11Eo7IG75rYdwZeIEo/RQTNRRqzYwqZmYAAAAASUVORK5CYII=\n",
      "text/latex": [
       "$\\displaystyle 0$"
      ],
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
   ]
  }
 ],
 "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.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
