Step 1: Formula:
The potential energy of a magnetic dipole in a field is \(U = -\vec{m}\cdot\vec{B} = -mB\cos\theta\), where \(\theta\) is the angle between \(\vec{m}\) and \(\vec{B}\).
The moment points along the field, so \(\theta = 0^{\circ}\).
Step 2: (a)(i) Potential energy:
\[ U_i = -mB\cos 0^{\circ} = -(5)(0.4)(1) = -2\ \text{J} \]
Step 3: (a)(ii) Work done in turning by 180 degrees:
After the turn, \(\theta = 180^{\circ}\), so \(U_f = -mB\cos 180^{\circ} = +mB = +2\ \text{J}\).
The work done by the external agent equals the change in potential energy:
\[ W = U_f - U_i = 2 - (-2) = 4\ \text{J} \]
Step 4: (b) Minimum potential energy:
\(U = -mB\cos\theta\) is smallest when \(\cos\theta = 1\), that is, when \(\theta = 0^{\circ}\). So the potential energy is minimum when the magnetic moment is parallel to the field, with value \(-mB = -2\) J. This is the position of stable equilibrium, and it is the case given in the question.
Final Answer:
(a)(i) \(U = -2\) J. (a)(ii) \(W = 4\) J. (b) The potential energy is minimum when the moment is along (parallel to) the field.\[ \boxed{U = -2\ \text{J}, \quad W = 4\ \text{J}} \]