Torque on Circular Current Loop in Uniform Magnetic Field I am trying to derive the expression: $\tau=\mu\times B$, for a circular current loop in a uniform magnetic field. $\mu$ is the magnetic moment of the loop, so it will be $\mu=IA$, where A is the area vector of the loop. So here is how I tried to prove the expression:
$$dF_m=Id\textbf{l}\times B$$
$$d\tau=r\times dF_m=r\times(Id\textbf{l}\times B)$$
$$d\textbf{l}=dxi+dyj+0k=(\cos\theta dr-r\sin\theta d\theta)i+(\sin\theta dr+r\cos\theta d\theta)j+0k$$
$$dr=0$$
$$d\textbf{l}=(-r\sin\theta d\theta)i+(r\cos\theta d\theta)j+0k$$
$$r\times dF_m=r\times(Id\textbf{l}\times B)=-Id\theta(r^2\sin^2\theta B_y+r^2\sin\theta \cos\theta B_x)i+Id\theta(r^2\sin\theta \cos\theta B_y+r^2\cos^2\theta B_x)j+0k$$
$$\tau=\oint d\tau=\int_{0}^{2\pi}(-Id\theta(r^2\sin^2\theta B_y+r^2\sin\theta \cos\theta B_x)i+Id\theta(r^2\sin\theta \cos\theta B_y+r^2\cos^2\theta B_x)j+0k)=I\pi r^2B_yi+I\pi r^2B_xj+0k$$
My problem is that the direction of the torque vector I arrived at is not correct. For a loop with an area vector $A=0i+0j+\pi r^2k$, $IA\times B=-I\pi r^2B_yi+I\pi r^2B_xj+0k$. 
I want to know where I messed up in this process.
 A: I did not follow your math, because frankly the algebra is tedious, but there are easier, less error-prone ways to derive the result you are after. Vector algebra identities are your friend.
The helpful one here is the ubiquitous identity
$$\vec A \times(\vec B \times \vec C) = (\vec A\cdot\vec C)\vec B-(\vec A\cdot\vec B)\vec C. $$
$$\vec\tau=I\oint{\vec r\times(d\vec\ell\times\vec B)}$$
$$ = I\oint{(\vec r\cdot\vec B)d\vec\ell-(\vec r\cdot d\vec\ell)\vec B}$$
$$ = I\oint{(\vec r\cdot\vec B)d\vec\ell}\tag{1}$$
$$ = I\oint{r(\hat r\cdot\vec B)(\hat z\times \hat r)d\ell}$$
$$ = Ir\hat z\times\oint{(\vec B\cdot\hat r)\hat rd\ell}$$
This integral is straightforward to evaluate in polar coordinates.
If you know vector calculus, you can also apply the identity
$$\oint\phi d\vec\ell=-\iint{\vec\nabla\phi\times d\vec S} $$
to $(1)$, with $\phi=\vec B\cdot\vec r$. Then,
$$\vec\tau=-I\iint{\vec\nabla(\vec B\cdot\vec r)\times\hat zdS}$$
$$=-I\iint{\vec B\times\hat zdS}$$
$$=IA\hat z\times\vec B.$$
