Solution (source code)

= Solution

Write the bead position in <Cartesian coordinates> as $\mathbf x_B=(a\cos\theta_B,a\sin\theta_B,b\theta_B)$. Differentiation gives $|\dot{\mathbf x}_B|^2=(a^2+b^2)\dot\theta_B^2$, while the free particle has $|\dot{\mathbf x}|^2=\dot r^2+r^2\dot\theta^2+\dot z^2$. Thus the <kinetic energy> is the sum of these squared <speeds> weighted by half the respective <mass>. The squared <spring> length is
$$
\ell^2=|\mathbf x-\mathbf x_B|^2=r^2+a^2-2ar\cos(\theta-\theta_B)+(z-b\theta_B)^2.
$$
A <spring> obeying <Hooke's law> with zero natural length has <potential energy> $k\ell^2/2$. Consequently \b[$L=T-k\ell^2/2$], and deleting the additive constant $-ka^2/2$ gives
$$
L=\frac m2(\dot r^2+r^2\dot\theta^2+\dot z^2)+\frac{M(a^2+b^2)}2\dot\theta_B^2-\frac k2\left[r^2-2ar\cos(\theta-\theta_B)+(z-b\theta_B)^2\right].
$$
The <spring> length is the straight separation of its endpoints, not distance measured along the <helix>. The fixed frictionless constraint is already incorporated by using the <generalized coordinate> $\theta_B$; it supplies no extra <potential energy>.