Solution (source code)

= Solution

Use the downward $y$ direction of the PDF diagram. The bob's Cartesian coordinates are
$$
x=s+\ell\sin\theta,\qquad y=\ell\cos\theta.
$$
Thus
$$
\dot x=\dot s+\ell\dot\theta\cos\theta,\qquad
\dot y=-\ell\dot\theta\sin\theta.
$$
The hinge and rod are massless, so only the bob contributes <kinetic energy>:
$$
T=\frac m2(\dot x^2+\dot y^2)
=\frac m2\left(\dot s^2+2\ell\dot s\dot\theta\cos\theta+\ell^2\dot\theta^2\right).
$$
Because gravity points along positive $y$, its <gravitational potential energy> is $-mgy=-mg\ell\cos\theta$. The zero-rest-length <spring> has <elastic potential energy> $ks^2/2$. Put $s=\ell\eta$ and divide $T-V$ by the positive constant $m\ell^2$. The equivalent <Lagrangian> is
$$
\boxed{L=\frac12\dot\eta^2+\dot\eta\dot\theta\cos\theta+\frac12\dot\theta^2
+\frac g\ell\cos\theta-\frac k{2m}\eta^2.}
$$
Multiplying the <action> by a nonzero constant leaves its stationary paths unchanged. This derivation is a direct use of <kinetic energy from Cartesian position vectors>; no independent kinetic term should be assigned to the massless support.