Constrained Optimization in the Calculus of Variations and Optimal Control Theory