What is the residue for this function How to find the residue of $\dfrac{1}{\tan(z)}$? I have calculated that it has a pole of order 2 . But I'm having trouble when using the residue theorem and I end up with a residue of $2$. However, wolfram alpha calculator says that the residue=$0$. 

Since, $ 1 + \cos z = 2\cos^2 \frac{z}{2} $, the function has second-order poles at $\frac{z}{2} = (n + \frac12)\pi$ or $z = (2n+1)\pi$
Let $w = z - (2n+1)\pi$, we can compute the residues 
$$ \begin{align} 
\operatorname*{Res}_{z=(2n+1)\pi} f(z) &= -\frac12 \lim_{z\to (2n+1)\pi} \frac{d}{dz}\left(\big(z -
 (2n+1)\pi\big)^2\sec^2 \frac{z}{2}\right) && w = z- (2n+1)\pi \\
&= -\frac{1}{2} \lim_{w\to0} \frac{d}{dw}\left( w^2 \sec^2 \left(\frac{w + (2n+1)\pi}{2}\right)\right) && \cos(z + n\pi) = (-1)^n\cos(z) \\
&= -\frac12 \lim_{w\to0} \frac{d}{dw} \left(w^2 \sec^2 \left( \frac{w+\pi}{2} \right)\right) && \cos(z+\pi/2) = -\sin z \\
&= -\frac12 \lim_{w\to0} \frac{d}{dw} \left(w^2 \csc^2 \frac{w}{2}\right) \\
&= -\frac12 \lim_{w\to0} \left(2w\csc^2 \frac{w}{2} - w^2\csc^2 \frac{w}{2} \cot \frac{w}{2} \right) \\
&= -\frac12 \lim_{w\to0} \frac{2w\sin \frac{w}{2} - w^2 \cos \frac{w}{2}}{\sin^3 \frac{w}{2}} \\
&= -\frac12 \lim_{w\to0} \frac{2w\left(\frac{w}{2}-\frac{w^3}{48} + O(w^5)\right) - w^2 \left(1-\frac{w^2}{8}+O(w^4)\right)}{\frac{w^3}{8} + O(w^5)} \\
&= -\frac12 \lim_{w\to0} \frac{\frac{w^4}{12} + O(w^6)}{\frac{w^3}{8} + O(w^5)} \\
&= 0
\end{align} $$
