Idea: A small loop can be considered as a magnetic dipole.
Thank you. Understood.
Brilliant approaches.
Actually the solutions are wrong, even if the final dependence gotten is correct. In the expression for force, when you differentiate magnetic field with respect to x, here x represents the length along the magnetic moment, which is perpendicular to the plane of the figure. It is not the distance from the line wire as has been done in the solutions. If the plane of the loop has been perpendicular to the plane of the paper, then the solutions would have been correct. I’ll post the correct solution tomorrow when I get time.
Oh sir got it.
You meant to say that…

Direction of magnetic field is in z and so is the gradient of B.

And M is also along z for the loop.

But magnetic field’s equation has distance along x axis in denominator.
Yes exactly. Try out the correct way and see if you get it.