Lagrangian formulation of mechanics