# Potential energy of magnetic dipole in non-uniform magnetic field

I want to understand why the potential energy of an ideal magnetic dipole with dipole moment $$\boldsymbol{m}$$ in a non-uniform magnetic field $$\boldsymbol{B}$$ (neglecting the term to keep the magnitude of the dipole moment fixed) is: $$$$U=-\boldsymbol{m}\cdot\boldsymbol{B}$$$$

The force on the dipole is: $$$$\boldsymbol{F}=\nabla(\boldsymbol{m}\cdot\boldsymbol{B})$$$$

The torque is: $$$$\boldsymbol{\tau}=\boldsymbol{m}\times\boldsymbol{B}$$$$

The derivations I found either compute (using the gradient theorem)

$$$$U=-\int_{\infty}^\boldsymbol{r}\boldsymbol{F}\cdot d\boldsymbol{l}$$$$

with assumptions on the field at infinity, or they use torque:

$$$$U=-\int_{\theta_0}^{\theta}\tau d\theta$$$$

The question is: why are these used separately? In terms of work, we must consider the work to bring the dipole from infinity (integrate the force) and then the work to rotate the dipole (integrate the torque), so what leads to this? Maybe I am considering two different energies? Because if the field is uniform the force is zero (thus zero work moving the dipole), but the torque is not, and we get that same energy from the torque.

• Note: when the question was asked I hadn't realized that a dipole has an additional degree of freedom which is the angular one. The potential energy is only one from which the forces $-\partial_\theta U$ and $-\nabla U$ can be derived. So restricting to one of the two cases (which is what I did) you need to integrate with respect to that variable. Commented Nov 11, 2022 at 20:50

If you bring in the dipole from infinity, you can first rotate it while it's at infinity (where, by assumption, the field vanishes, and thus its potential energy is still zero), and then translate it to its final location. In doing so against a force $$\nabla (m \cdot B)$$, you give it potential energy in the amount $$-m \cdot B$$.