The Calculus of Variations and Optimal Control