TITLE: How to evaluate the integral $\int_0^{\pi}\frac{a^n\sin^2x+b^n\cos^2x}{a^{2n}\sin^2x+b^{2n}\cos^2x}dx$?
QUESTION [5 upvotes]: Evaluate the integral $$\int_0^{\pi}\frac{a^n\sin^2x+b^n\cos^2x}{a^{2n}\sin^2x+b^{2n}\cos^2x}dx.$$

I have no idea. 
$$\int_0^{\pi}\dfrac{a^n\sin^2x+b^n\cos^2x}{a^{2n}\sin^2x+b^{2n}\cos^2x}dx=\int_0^{\pi/2}\dfrac{a^n\sin^2x+b^n\cos^2x}{a^{2n}\sin^2x+b^{2n}\cos^2x}dx=\int_0^{\pi/2}\dfrac{a^n\tan^2x+b^n}{a^{2n}\tan^2x+b^{2n}}dx$$
I try the substitution $\tan{x}=t$, but it doesn’t work.

REPLY [2 votes]: A complex analysis approach. I assume that $a>b>0$ (the general case is left to the reader).
Let $A=a^n$, $B=b^n$, and $t=2x$, then, by the half-angle  formulas, the given integral is
$$\begin{align}
I&=\frac{1}{2}\int_0^{2\pi}\frac{A(1-\cos(t))+B(1+\cos(t))}{A^2(1-\cos(t))+B^2(1+\cos(t))}dt
=\frac{1}{2}\int_0^{2\pi}\frac{A+B +(B-A)\cos(t)}{A^2+B^2 +(B^2-A^2)\cos(t)}dt
\end{align}$$
By letting $z=e^{it}$, we have that $\cos(t)=(z+1/z)/2$, and
$$\begin{align}I&=\frac{1}{2}\int_{|z|=1}\frac{2A+2B +(B-A)(z+1/z)}{2A^2+2B^2 +(B^2-A^2)(z+1/z)}\frac{dz}{iz}\\
&=\frac{1}{2i}\int_{|z|=1}f(z) dz\\
&=\pi\left(\text{Res}(f,z=0)+\text{Res}\left(f,z=\frac{A-B}{A+B}\right)\right)\\
&=\pi\left(\frac{1}{A+B}+\frac{1}{A+B}\right)=\frac{2\pi}{a^n+b^n}
\end{align}$$
where we noted that $0<\left|\frac{A-B}{A+B}\right|<1<\left|\frac{A+B}{A-B}\right|$, and we set
$$f(z):=\frac{(A-B)z^2-2(A+B)z+(A-B)}
{z((A-B)z-(A+B))((A+B)z-(A-B))}.$$