Solution (source code)

= Solution

Let the pivot's prescribed horizontal <position> be $x(t)$ and measure $\theta$ from the downward vertical. The bob's coordinates are $X=x+l\sin\theta$ and $Y=-l\cos\theta$. Therefore
$$
\dot X^2+\dot Y^2=\dot x^2+2l\dot x\dot\theta\cos\theta+l^2\dot\theta^2.
$$
With zero <gravitational potential energy> at pivot height, the bob's <Lagrangian> is
$$
\boxed{\mathcal L=\frac m2\bigl(\dot x^2+2l\dot x\dot\theta\cos\theta+l^2\dot\theta^2\bigr)+mgl\cos\theta.}
$$
Here $x(t)$ is a prescribed input, not yet a free coordinate. Terms depending only on that prescribed <time> function can be dropped without changing the $\theta$ equation. The moving block's own <kinetic energy> becomes relevant when its motion is free in part (d).