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$? 
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. 
 A: 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))}.$$
A: Your approach does work if you would do it correctly. Assume $a\neq 0$ and $b\neq 0$, why? Otherwise the integral is boring. Also assume that $|a|\neq |b|$ for the same reason. Let:
\begin{align}
I=\int^{\pi}_0 \frac{a^n\sin^2(x)+b^n\cos^2(x)}{a^{2n}\sin^2(x)+b^{2b}\cos^2(x)}dx = 2\int^{\pi/2}_0 \frac{a^n\sin^2(x)+b^n\cos^2(x)}{a^{2n}\sin^2(x)+b^{2b}\cos^2(x)}dx
\end{align}
Set $\tan(x) =t$ and get $\sin(x)=\frac{t^2}{1+t^2}$ and $\cos(x)=\frac{1}{1+t^2}$ and $dx = \frac{dt}{1+t^2}$ so that the original integral $I$ becomes:
\begin{align}
I = 2\int^\infty_0 \frac{a^nt^2+b^n}{(1+t^2)(a^{2n}t^2+b^{2n})}dt = \frac{1}{a^{2n}} \int^{\infty}_{-\infty} \frac{a^nt^2+b^n}{(1+t^2)(t^2+\frac{b^{2n}}{a^{2n}})} dt
\end{align}
Using a semi cirkel contour in the upper half plane and using the Residue Theorem we get:
\begin{align}
I = \frac{1}{a^{2n}} 2\pi i \left( \text{Res}_{z=i} \frac{a^nz^2+b^n}{(1+z^2)(z^2+\frac{b^{2n}}{a^{2n}})}  + \text{Res}_{z=i|b|^n/|a|^n} \frac{a^nz^2+b^n}{(1+z^2)(z^2+\frac{b^{2n}}{a^{2n}})}\right)
\end{align}
Calculating these residues:
\begin{align}
\text{Res}_{z=i} \frac{a^nz^2+b^n}{(1+z^2)(z^2+\frac{b^{2n}}{a^{2n}})}   = \frac{-a^n+b^n}{2i (-1+\frac{b^{2n}}{a^{2n}})}
\end{align}
And the other one:
\begin{align}
\text{Res}_{z=i|b|^n/|a|^n} \frac{a^nz^2+b^n}{(1+z^2)(z^2+\frac{b^{2n}}{a^{2n}})} = \frac{-a^n\frac{b^{2n}}{a^{2n}}+b^n}{2i\frac{|b|^n}{|a|^n}(1-\frac{b^{2n}}{a^{2n}})}
\end{align}
If we put everything together we get:
\begin{align}
I = \frac{\pi}{a^{2n}}\left( \frac{-a^n+b^n}{ (-1+\frac{b^{2n}}{a^{2n}})} + \frac{-a^n\frac{b^{2n}}{a^{2n}}+b^n}{\frac{|b|^n}{|a|^n}(1-\frac{b^{2n}}{a^{2n}})}\right)
\end{align}
Simplifying a bit gives us:
\begin{align}
I = \frac{\pi}{(b^{2n}-a^{2n})} \left( b^n-a^n+\frac{|a|^n}{|b|^n}\left( \frac{b^{2n}}{a^{n}}-b^n\right)\right)
\end{align}
