Here's an example computing integral 3 ways: (1): Numerically, (2): Using the built-in Residue
command, and (3): Using the built-in Series
command:
a = 3;
r = 1;
n = 3;
t = Pi/4;
theInt = (
n Cos[x] (-a + 2 r Cos[x]) Sin[n (x + t)] - (a - 2) Cos[
n (x + t)] Sin[x])/(a - 2 r Cos[x])^2;
poles = x /. Solve[(a - 2 r Cos[x]) == 0, x]
poles // N
The poles are in this case $\pm\arccos(3/2)+2k\pi,\quad k\in\mathbb{Z}$ and $\pm \arccos(3/2)\approx \pm 0.962424i$ which are in the unit circle.
(1): First numerically integrate it over the unit circle via $x=e^{i\theta}$:
NIntegrate[(theInt I Exp[I theta]) /. x -> Exp[I theta], {theta, 0, 2 Pi}]
(* 8.56637*10^-11 + 106.629 I *)
which gives approx $106.629i$ and a small residual real part.
(2): Use Residue
to compute the residues at these poles and the Residue Theorem to compute the integral:
r1 = Residue[theInt, {x, -ArcCos[3/2]}] // N
r2 = Residue[theInt, {x, ArcCos[3/2]}] // N
2 Pi I (r1 + r2) // N
(* 8.48528 - 8.53815 I
8.48528 + 8.53815 I
0. + 106.629 I *)
(3): Expand the integrand around each pole using Series
and extract the $\displaystyle \frac{1}{x\pm \arccos(3/2)}$ terms as the residues:
series1 = Series[theInt, {x, ArcCos[3/2], 4}];
residue1 = Coefficient[series1, 1/(x - ArcCos[3/2])];
series2 = Series[theInt, {x, -ArcCos[3/2], 4}];
residue2 = Coefficient[series2, 1/(x + ArcCos[3/2])];
residue1 // N
residue2 // N
(*
Out[94]= 8.48528 + 8.53815 I
Out[95]= 8.48528 - 8.53815 I
(*)