<s>[INST] Changing variable - Integration goes wrong. I was trying to do the integration
$$I=\frac{\pi}{2}\int_0^\pi \frac{dx}{a^2\cos^2x + b^2\sin^2x}$$
If I divide throughout by $\cos^2x$ and use substitution ($t=\tan x$),
I obtain$$I=\frac{\pi}{2}\int_0^0\frac{dt}{a^2+(bt)^2} $$
This would be evaluated to be $0$.
But however its actual answer is $$\frac{\pi^2}{2ab}$$
which can be obtained by using properties of definite integrals to change the limit to $0$ to $\frac{\pi}{2}$ and then splitting it from  $0$ to $\frac{\pi}{4}$ and  $\frac{\pi}{4}$ to $\frac{\pi}{2}$ ,dividing throughout by $\cos^2x$ and $\sin^2x$ respectively and then substituting ($t=\tan x$) and ($t=\cot x$) respectively.
Can anyone please tell me what is wrong in the first approach.
 [/INST] The reason why your substitution doesn't work is due to the singularity at $\frac {\pi}2$. Indeed, $\tan\left(\frac {\pi}2\right)$ isn't defined. However, you can remedy this by splitting up the integral along the singularity$$\begin{align*}\int\limits_0^{\pi}\frac {\mathrm dx}{a^2\cos^2x+b^2\sin^2x} & =\int\limits_0^{\pi/2}\frac {\mathrm dx}{a^2\cos^2x+b^2\sin^2x}+\int\limits_{\pi/2}^{\pi}\frac {\mathrm dx}{a^2\cos^2x+b^2\sin^2x}\\ & =\int\limits_0^{\pi/2}\frac {\mathrm dx}{a^2\cos^2x+b^2\sin^2x}+\int\limits_0^{\pi/2}\frac {\mathrm dx}{a^2\sin^2x+b^2\cos^2x}\\ & =\int\limits_0^{\infty}\frac {\mathrm dx}{a^2+b^2x^2}+\int\limits_0^{\infty}\frac {\mathrm dx}{b^2+a^2x^2}\\ & =\frac 1{ab}\left[\arctan\left(\frac {bx}a\right)+\arctan\left(\frac {ax}b\right)\right]\,\Biggr\rvert_0^{\infty}\end{align*}$$So now, we get that$$\frac {\pi}2\int\limits_0^{\infty}\frac {\mathrm dx}{a^2\cos^2x+b^2\sin^2x}\color{blue}{=\frac {\pi^2}{2ab}}$$
</s>