lagrangian mechanics generalized