Variational Calculus and Optimal Control