The script calculates the path of a thrown mass, in the single vertical dimension. The true path of an object minimizes the Action integral S.
The Lagrangian L is given by L=T-V. Discretization of the Lagrangian gives
Which gives the discrete Action
Varying the path leads to different Actions, and varying w.r.t each node on the grid, gives an explicit linear system of equations.
The problem can also be formulated as an unconstrained optimization problem. For 5 varying points, with 2 constrained end points, we can define