Consider a pendulum of length $h$ with a bob of mass $m$ it is held horizontally at and angle of $90^{\circ}$ with the vertical. A rod of mass $M$ and length $h$ is pivoted at its upper end and this pivot coincides with the point of suspension of the pendulum. The rod hangs downwards along the vertical. The pendulum is released. It collides with the rod and sticks there. Find the angle rotated by the rod.
This can be easily accomplished using conservation of mechanical energy. Clearly, the initial energy of the system is purely potential energy:
$$E_i = U_{bob} = mgh \tag1$$
The final potential energy, when the rod has rotated through $\theta$ is also purely potential energy:
$$E_f = U_{bob} + U_{rod}$$
$$U_{bob} = mg(h - h\cos\theta) = mgh(1 - \cos\theta)$$
$$U_{rod} = \int dU = \int dmdhg$$
Consider a small length $dx$ on the rod at a distance $x$ from the top. The potential energy of this length is $dm(h - x\cos\theta)g$. The mass per unit length of the rod is $\frac{M}{h}$, so $dm = \frac{Mdx}{h}$. Putting these into the integral and integrating over all segments on the length of the rod, we get:
$$U_{rod} = \int_0^h \left(\frac{Mdx}{h}\right)(h - x\cos\theta)g = \frac{Mg}{h}\int_0^h (h - x\cos\theta)dx$$
$$= \left[Mgx - \frac{Mgx^2\cos\theta}{2h}\right]_0^h = Mgh - \frac{Mgh\cos\theta}{2}$$
$$\therefore E_f = mgh - mgh\cos\theta + Mgh - \frac{Mgh\cos\theta}{2}$$
Equating the above with $(1)$:
$$mgh = mgh - mgh\cos\theta + Mgh - \frac{Mgh\cos\theta}{2}$$
$$\implies Mgh = \cos\theta gh\left(m + \frac{M}{2}\right)$$
$$\implies \boxed{\cos\theta = \frac{2M}{2m + M}}$$
But consider the case where the bob has a mass of $100 \ \rm{grams}$ and the rod a mass of $240 \ \rm{grams}$.
$$\cos\theta = \frac{2\cdot 0.24}{2\cdot0.1 + 0.24} = \frac{0.48}{0.44} > 1$$
which is clearly not possible. But, from experience, we know that the rod will rotate through some valid angle. Where did I go wrong?