Just a quick example of how to use the Lagrangian to get the equations of motion of a simple pendulum as well as a pendulum with constant acceleration in the x direction (pendulum on train/truck).
The image is from Classical Dynamics by Thornton and Marion Fig 7-4 p244.