Residue of $\frac{g(z)}{\cos^{2}z}$ I would like to show that the residue of the function $$\text{Res}\left(\frac{g(z)}{\cos^{2}z}\right) = g'(z_n)$$ at $z_{n}=(n+\frac{1}{2})\pi$, where $g$ is analytic.
I tried the Limit formula for higher order poles and it fails. What other method can  I use?

Using the addition theorem for the cosine and the fact that
$\sin(z_n) = \pm 1$, $\cos(z_n) = 0$, you can compute the initial part of the
Taylor series for $\cos^2(z_n + h)$ at $h = 0$:
$$
\cos^2(z_n + h) = \sin^2(h) = \bigl( h + \frac{h^3}{3!} + O(h^5) \bigr)^2 \\
 = h^2 \bigl( 1 + \frac{h^2}{6} + O(h^4) \bigr)^2 \\
 = h^2 \bigl( 1 + \frac{h^2}{3} + O(h^4) \bigr) 
\quad \text{ for } h \to 0
$$
It follows that
$$
\frac{1}{\cos^2(z_n + h)} = \frac{1}{h^2} \bigl( 1 - \frac{h^2}{3} + O(h^4) \bigr) \\
 = \frac{1}{h^2} - \frac 13 + O(h^2)
$$
Now multiply that with
$$
  g(z_n + h) = g(z_n) + g'(z_n) h + O(h^2)
$$
to get
$$
\frac{g(z_n+h)}{\cos^2(z_n + h)} = \frac{g(z_n)}{h^2} + \frac{g'(z_n)}{h} + O(1)
\quad \text{ for } h \to 0
$$
Finally, substitute $z = z_n + h$:
$$
\frac{g(z)}{\cos^2(z)} = \frac{g(z_n)}{(z-z_0)^2} + \frac{g'(z_n)}{z-z_n} + O(1)
\quad \text{ for } z \to z_n
$$
and the residuum is the coefficient of $(z-z_n)^{-1}$ in the
Laurent series, which is $g'(z_n)$.
