Solution (source code)

= Solution

Let $s$ be distance along the rod from its fixed end. The position of that material point is $s\,n(t)$, where $n=(\sin\theta\cos\phi,\sin\theta\sin\phi,-\cos\theta)$ is a <unit vector>. Its <velocity> is $s\dot n$, and direct differentiation gives
$$
|\dot n|^2=\dot\theta^2+\sin^2\theta\,\dot\phi^2.
$$
The uniform linear <mass density> is $M/a$. Integrating the elemental <kinetic energy> therefore proves, rather than assumes, the rod formula:
$$
T=\frac12\int_0^a s^2|\dot n|^2\frac Ma\,ds=\boxed{\frac{Ma^2}{6}(\dot\theta^2+\sin^2\theta\,\dot\phi^2).}
$$
Equivalently, its <moment of inertia> about a perpendicular axis through the pivot is $Ma^2/3$.