Fundamental Theorem of Calculus Confusion regarding atan According to this site,
$$ \int \frac{1}{a^2 \cos^2(x) + b^2 \sin^2(x)} \,dx =\frac{1}{ab} \arctan\left(\frac{b}{a} \tan(x)\right)$$
Thus,
$$ \int_0^{\pi} \frac{1}{a^2 \cos^2(x) + b^2 \sin^2(x)} \, dx =\frac{1}{ab} \arctan\left(\frac{b}{a} \tan(\pi)\right)-\frac{1}{ab} \arctan\left(\frac{b}{a} \tan(0)\right)=0-0=0$$
But in fact value of integral is not zero.
What am I doing wrong?

First, let us assume that $a, b > 0$ without loss of generality.  Then in this regime, $f(x) = (a^2 \cos^2 x + b^2 \sin^2 x)^{-1}$ is clearly a well-defined function everywhere, and is periodic with period $\pi$.  However, the antiderivative is not unique, and the particular choice of antiderivative $$F(x) = \frac{1}{ab} \tan^{-1} \left( \frac{b}{a} \tan x \right)$$ may not be continuous over a given interval.  For example, if we choose the branch of $\tan^{-1}$ that restricts the range to lie in $(-\pi/2, \pi/2)$, then you get this picture for $a = 2$, $b = 0.5$:

As you can see, there is a jump discontinuity in the antiderivative at $x = \pi/2$ that could be rectified by choosing a different branch of the inverse tangent; e.g., we could choose $\tan^{-1}$ to have the range $[0,\pi)$.  This fixes the discontinuity at $\pi/2$ so that a definite integral containing this point will not result in an incorrect evaluation.

In general, it is important when dealing with branches of multivalued functions to choose the branch appropriate to the interval or domain of integration, so as to avoid these problems.

An example of how you could specify an antiderivative that is continuous for all real $x$ provided that we state that the range of $\tan^{-1}$ is $(-\pi/2,\pi/2)$, is by writing it as $$F(x) = \begin{cases} \displaystyle \frac{1}{ab} \left( \tan^{-1} \left(\frac{b}{a} \tan x \right) + \pi \left(\lfloor 2x/\pi \rfloor - \lfloor x/\pi \rfloor\right) \right), & 2x/\pi \not \in \{\pm 1, \pm 3, \ldots\} \\ \displaystyle \frac{x}{ab}, & 2x/\pi \in \{\pm 1, \pm 3, \ldots\}. \end{cases}$$ 
But I think this is a rather complicated way to express the antiderivative.  Instead, it might be better to state that the branch of the inverse tangent that is chosen depends on the argument of $x$; i.e., if we define $y = \tan^{-1} c \tan x$ for some $0 < c < \infty$, then $y$ is chosen such that $x, y \in ((2m-1)\pi/2, (2m+1)\pi/2)$ for a suitable integer $m$.
