(d) The potential energy of a magnetic dipole of magnetic moment M placed in magnetic field H is given as
$U_{\theta} = - \mathbf{M.H} = - MH\cos\theta$
Where $\theta$ is angle between the vector M and H. Initially the dipole possesses minimum potential energy $U_{0},$ therefore work requires to turn through angle $\theta$ is
$W = U_{\theta} - U_{0}$
$\ \ \ \ \ \ = - MH\cos{\theta - ( - MH\cos\theta)}$
$\ \ \ \ \ \ = - MH\cos{\theta + MH}$
$W = MH(1 - \cos\theta)$