Does an analytical form exist for the following integral I have an integral
$$f(n,a)=\int_0^{2\pi}\mathop{\mathrm{d}x}\frac{\cos(nx)\cos^2x}{1-a\cos^2x},$$
where $n$ is an even integer and $0<a<1$ is a real number. Does an analytical form exist for this integral?
Edit: Here is a partial answer that I discovered:
$$\int_0^{2\pi}\mathop{\mathrm{d}x}\frac{\cos(nx)}{1-a\cos^2x}=-\frac{2\pi}{\sqrt{1-a}}\left(\frac{1-\sqrt{1-a}}{\sqrt{a}}\right)^n,\qquad a<1, n>0.$$
$n$ is even.
 A: The answer is 
$$f(n, a) = \frac{2\pi}{a\sqrt{1-a}}\left(\frac{1-\sqrt{1-a}}{\sqrt{a}}\right)^n \tag{1}$$
for $0 < a < 1$ and $n > 0$ an even integer; we also have $$f(0, a) = \frac{2\pi}{a \sqrt{1-a}} - \frac{2\pi}{a}$$
which (mysteriously) happens to equal what $\sqrt{a}f(1, a)$ would be if we put $n=1$ in formula $(1)$.
First, consider the related integral $$g(n, a) = \int_0^{2\pi}\frac{\cos nx}{1-a\cos^2 x}\,dx$$ 
which is useful because 
$$g(n, a) - a f(n, a) = \int_0^{2\pi} \cos nx\,dx = \begin{cases}2\pi, & n = 0 \\ 0, & n \ne 0.\end{cases} \tag{2}$$
Express $g$ as a contour integral via $z = e^{ix}$, 
noting that $\cos nx = \frac{1}{2}(z^n + z^{-n})$ and $dz = iz\,dx$. 
After some simplification, we get:
$$g(n,a) = 2i \int_{|z|=1} \frac{z^n + z^{-n}}{az^4 + 2(a-2)z^2 + a} z\,dz. \tag{3}$$
The polynomial $Q_a(z)$ in the denominator has four roots, 
but since it's biquadratic they are easy to determine explicitly. 
The quadratic formula gives 
$$\pm\sqrt{\frac{2}{a}\left(1\pm\sqrt{1-a}\right)-1}$$
and a stroke of luck denesting radicals gives 
$$\pm\frac{1\pm\sqrt{1-a}}{\sqrt{a}}.$$
It isn't hard to see (either by elementary means or Rouché's theorem) that these four roots are real and distinct, and precisely two of them lie within the unit disk: $\alpha = (1-\sqrt{1-a})/\sqrt{a}$ and $-\alpha$. Let's call the other pair $\pm\beta$. From the coefficients of $Q_a$ we deduce that $\alpha^2 \beta^2 = 1$.
Write $P_n(z) = z(z^n + z^{-n})$. The integrand in $(3)$ has simple poles at $\alpha$ and $-\alpha$ with matching residues there: $$\frac{P(\pm\alpha)}{Q_a'(\pm\alpha)} = -\frac{1}{8\sqrt{1-a}}\left(\alpha^n + \beta^n\right).\tag{4}$$
For $n > 0$ there is also a pole at the origin of order $n-1$, and this is painful to deal with.  
Here's what I did. (This may not be the best approach.) 
Write
$$\frac{1}{aw^2 + 2(a-2)w + a} = \sum_{k=0}^\infty c_k w^k$$
as a (formal) power series.
Since this is a rational function, 
the coefficients $c_k$ satisfy a recurrence with a closed form involving powers of the roots $\alpha^2$ and $\beta^2$. Cross multiplying, we see that
$$c_0 = \frac{1}{a},\quad c_1 = \frac{2(2-a)}{a^2},\quad c_k = a c_1 c_{k-1} - c_{k-2}.$$
Knowing that the general solution is of the form $c_k = \lambda (\alpha^2)^k + \mu (\beta^2)^k$, plug in the initial conditions and solve: 
$$\lambda = \frac{a-2+2\sqrt{1-a}}{4a\sqrt{1-a}}$$
$$\mu = \frac{2-a+2\sqrt{1-a}}{4a\sqrt{1-a}} = \frac{1}{a} - \lambda.$$
We seek the coefficient of $z^{-1}$ in the integrand, which looks like
$$z(z^n + z^{-n})\sum_{k=0}^\infty c_k z^{2k}$$
around the origin, so we want $2k + 1 - n = -1$, or $k = \frac{n}{2}-1$. 
Thus, the residue is $$\lambda\beta^2\alpha^n + \mu\alpha^2\beta^n\tag{5}$$
and combining $(5)$ with (the double contribution of) $(4)$ we obtain, by the residue theorem, 
$$g(n, a) = 4\pi\left\{\left(\frac{1}{4\sqrt{1-a}}-\lambda\beta^2\right)\alpha^n + \left(\frac{1}{4\sqrt{1-a}}-\mu\alpha^2\right)\beta^n\right\}.$$
Miraculously, the coefficient of $\beta^n$ vanishes. 
Simplifying, we conclude that 
$$g(n, a) = \frac{2\pi}{\sqrt{1-a}}\left(\frac{1-\sqrt{1-a}}{\sqrt{a}}\right)^n$$
where, of course, 
the sign of the root $\alpha$ does not matter as $n$ is even. This in $(2)$ yields $(1)$.

Update. A much simpler way to evaluate $g(n, a)$ has been brought to my attention. 
$$g(n, a) = \int_0^{2\pi} \frac{e^{ix}}{1-a\cos^2 x}\,dx$$
because the imaginary part (the sine integral) vanishes (the integrand is odd); 
now let $z = e^{ix}$. The integral becomes
$$4i \int_{|z|=1} \frac{z^{n+1}}{Q_a(z)}\,dz$$ 
which equals
$$(2\pi i)(4 i)\frac{2\alpha^n}{-8\sqrt{1-a}} = \frac{2\pi \alpha^n}{\sqrt{1-a}}$$
by the residue theorem.
A: By expanding $(1-a\cos^2 x)^{-1}$ as $\sum_{k=0}^{\infty}(a\cos^2 x)^k$, you obtain
$$
f(n,a)=\sum_{k=0}^{\infty} a^k \int_{0}^{2\pi} dx \cos(nx) \cos^{2k+2} x.
$$
Each cosine can be written as $\cos u = \frac{1}{2}(e^{iu} + e^{-iu})$, and terms of the form $\int_{0}^{2\pi}e^{imu}$ vanish unless $m=0$, in which case they evaluate to $2\pi$.  Counting the number of non-vanishing terms (there are none for $k<n/2-1$), we get
$$
f(n,a)=2\pi\sum_{k=n/2-1}^{\infty}\frac{a^k}{2^{2k+2}}{{2k+2}\choose{k+1+n/2}}=\frac{\pi}{2}\sum_{k=n/2-1}^{\infty}\left(\frac{a}{4}\right)^k{{2k+2}\choose{k+1+n/2}}.
$$
According to WolframAlpha, the sum does have an ugly analytical form for general $n$, in terms of hypergeometric functions, which I won't reproduce here.  Checking one value: for $n=2$, the sum is
$$
f(2,a)=\frac{\pi}{2}\sum_{k=0}^{\infty}\left(\frac{a}{4}\right)^k{{2k+2}\choose{k+2}}=4\pi\left(\frac{1-a/2-\sqrt{1-a}}{a^2\sqrt{1-a}}\right),
$$
so $f(2,1/2)=4\pi\left(3\sqrt{2}-4\right)$.  A direct evaluation of the integral (again in WolframAlpha) agrees with this value for $f(2,1/2)$.
A: I'm kind of surprised that this problem hasn't been attacked with a geometric series yet. Let $0<b<1$. Then
$$\sum_{k=0}^{\infty}b^ke^{ik\theta}=\sum_{k=0}^{\infty}b^k\cos k\theta+i\sum_{k=0}^{\infty}b^k\sin k\theta=\frac1{1-be^{i\theta}}=\frac{1-b\cos\theta+ib\sin\theta}{1-2b\cos\theta+b^2}$$
Taking real parts and setting $\theta=2x$,
$$\begin{align}1+\sum_{k=1}^{\infty}b^k\cos2kx&=\frac{1-b(2\cos^2x-1)}{1-2b(2\cos^2x-1)+b^2}\\
&=\frac1{1+b}+\frac{\frac{2b(1-b)}{1+b}\cos^2x}{(1+b)^2-4b\cos^2x}\end{align}$$
Then
$$\frac b{1+b}+\sum_{k=1}^{\infty}b^k\cos2kx=\frac{\frac{2b(1-b)}{(1+b)^3}\cos^2x}{1-\frac{4b}{(1+b)^2}\cos^2x}$$
Solving $a=\frac{4b}{(1+b)^2}$ for
$$b=\frac{2-a\pm\sqrt{1-a}}a=\frac{\left(1-\sqrt{1-a}\right)^2}a$$
And inserting this result for $b$ throughout,
$$\frac{1-\sqrt{1-a}}2+\sum_{k=1}^{\infty}\frac{\left(1-\sqrt{1-a}\right)^{2k}}{a^k}\cos2kx=\frac{\frac a2\sqrt{1-a}\cos^2x}{1-a\cos^2x}$$
This shows that $$f(0,a)=2\pi\frac{1-\sqrt{1-a}}{a\sqrt{1-a}}$$
And
$$f(n,a)=\frac{2\pi}{a\sqrt{1-a}}\frac{\left(1-\sqrt{1-a}\right)^n}{a^{n/2}}$$
For positive even n, in agreement with other results, but I think the tools used here are a little simpler.
