Variational methods for problems in mechanics Hamiltonian and Lagrangian mechanics mathematics