Interaction between magnetic moments and magnetic field Consider a particle with a magnetic moment $\vec{m}$. For simplicity, suppose that this particle is a circle in the plane $xy$ which can rotate around its center of mass along the $z$ axis. If this particle is subject to an external magnetic field $\vec{B}$ in the plane $xy$, then its potential energy is:
$$ U = -\vec{m} \cdot \vec{B} = -mB\cos(\theta),$$
where $m = \|\vec{m}\|$, $B = \|\vec{B}\|$, and $\theta$ is the angle between $\vec{m}$ and $\vec{B}$.
Reading around, I found that the exerted torque on the particle is 
$$\vec{\tau} = \vec{m} \times \vec{B}.$$
In the planar case I'm working on, $\vec{\tau}$ has only the $z$ component, which is 
$$\tau_z = mB\sin(\theta).$$
Anyway, If I want to obtain the torque from the potential energy, I get this:
$$\tau_z = -\frac{\partial U}{\partial \theta} = -\left[-mB(-\sin(\theta)) \right] = -mB\sin(\theta).$$
Where is the truth? Am I wrong with my calculations?
 A: The difference is only how you define $\theta$ and the zero of potential energy.
The $\cos \theta$ expression takes the zero of potential energy to be when $\theta = \frac \pi 2$ whereas you derivation with $\sin \theta$ in it takes the zero of potential to be when $\theta = 0$.
A: Must admit this got me really worried, and I wondered if the problem was maybe in the use of $\bf{\tau} = \bf{r \times F}$ and identifying the force with the (negative) gradient of some potential. Then, I really got worried because it seemed to me that the same problem would occur if you were to make similar calculations with determining the torque on an electric dipole. However consider the following figure which shows a magnetic dipole, $\bf{m}$ aligned in the $x, y$ plane with the magnetic field, $\bf{B}$, taken to lie along the $y$ axis.

Then when you use plane polar coordinates, the torque is given as $\bf{\tau = -r \times \nabla}$ $V$, with $V = -\bf{m.B} =$ $-m \, B \, cos \theta$. When the vector ${\bf r}$ is taken in the $x, y$ plane the torque reduces to $-[\frac{\partial V}{\partial \phi}\bf{ k} - \rho \frac{\partial V}{\partial z} {\bf \phi}]$ which further reduces to $-\frac{\partial V}{\partial \phi}\bf{ k}$ since the potential does not depend on $z$. This is, I think, where you are starting from? I think your mistake is that $\frac{\partial}{\partial \phi} \ne \frac{\partial}{\partial \theta}$, but rather $\frac{\partial}{\partial \phi} = -\frac{\partial}{\partial \theta}$ (the angles $\phi$ and $\theta$ are not independent, here $\phi + \theta = \frac{\pi}{2}$ so $d \phi = - d \theta$.
A: Maybe, I found the solution. let's denote with $\theta_k$ the rotation around $k$-axis. Suppose that both $\vec{m}$ and $\vec{B}$ belongs to $xy$ plane. That is:
$$\vec{m} = \begin{pmatrix}
m \cos(\theta_z)\\
m \sin(\theta_z)\\
0
\end{pmatrix} ~\text{and} ~\vec{B} = \begin{pmatrix}
B \\
0\\
0
\end{pmatrix}.$$
The torque using the formula $\vec{\tau} = \vec{m} \times \vec{H}$ is:
$$
\vec{\tau} = \det\begin{pmatrix}
\vec{x} & \vec{y} & \vec{z} \\
m \cos(\theta_z) & m \sin(\theta_z) & 0\\
B & 0 & 0
\end{pmatrix} = 
\begin{pmatrix}
0 \\
0\\
-mB \sin(\theta_z)
\end{pmatrix}.$$
On the other hand, if I evaluate the torque using the potential $U = -\vec{m} \cdot \vec{B} = -mB \cos(\theta_z)$, I get:
$$\vec{\tau} = -\nabla U = -\begin{pmatrix}
\displaystyle\frac{\partial U}{\partial \theta_x} \\
\displaystyle\frac{\partial U}{\partial \theta_y}\\
\displaystyle\frac{\partial U}{\partial \theta_z}
\end{pmatrix} = 
\begin{pmatrix}
0 \\
0\\
-mB \sin(\theta)
\end{pmatrix}.$$
At the end of the story, $-mB \sin(\theta)$ is just the $z$  component of the torque.
