Why these integrals are evaluated differently? $\cos(x)/(a-b\cos(x))$ In attempt to solve electrostatics problem I came up to this integral that I am trying to integrate:
$$\int_0^{2\pi}\frac{\cos(x)}{a-b\cos(x)} \, dx$$ where $a>b$ and both are real numbers.
For the domain $[0, 2\pi]$ this function is symmetric at $\pi$ (Plot: 1)
So it is expected that:
$$\int_0^{2\pi}\frac{\cos(x)}{a-b\cos(x)}dx = 2\int_0^{\pi}\frac{\cos(x)}{a-b\cos(x)}dx$$
I could not integrate it by hand (maybe some of you guys can?). But Wolfram Mathematica gives weird answers for both of these integrals - however if evaluated they lead to same answer!
This is what Mathematica gives me:
$$\int_0^{2 \pi } \frac{\cos (x)}{a-b \cos (x)} \, dx = \frac{2 \pi  \left(a \left(\sqrt{\frac{a+b}{a-b}}-1\right)-b\right)}{b (a+b)}$$
$$\int_0^{\pi } \frac{\cos (x)}{a-b \cos (x)} \, dx = -\frac{\frac{a \log \left(\frac{a+b}{\sqrt{b^2-a^2}}\right)}{\sqrt{b^2-a^2}}-\frac{a \log \left(-\frac{a+b}{\sqrt{b^2-a^2}}\right)}{\sqrt{b^2-a^2}}+\pi }{b}$$
If I add these logarithms it gives log(-1) which is imaginary, how come these integrals are the same?

These integrals are very similar to the ones for which Euler introduced the tangent half-angle substitution, sometimes erroneously called the "Weierstrass substitution" (I hope the quotation marks are intimidating . . . . .)
\begin{align}
t & = \tan\frac x 2 \\[8pt]
2\arctan(t) & = x \\[8pt]
\frac{2\,dt}{1+t^2} & = dx \\[8pt]
\cos x & = \cos(2\arctan t) = 2\cos^2(\arctan t) - 1 \\[8pt]
& = 2\left(\frac{1}{\sqrt{1+t^2}}\right)^2 - 1 = \frac{1-t^2}{1+t^2}
\end{align}
(and $\sin x$ can be found similarly, but we don't need it here, and neither did Euler in the integrals he did this way that I am aware of).
So we have
$$
\begin{align}
\int_0^{2\pi} \frac{\cos x}{a-b\cos x}\,dx & = \int_{-\infty}^\infty \frac{\frac{1-t^2}{1+t^2}}{a-b\frac{1-t^2}{1+t^2}}\cdot\frac{2\,dt}{1+t^2} \\[8pt]
& = \int_{-\infty}^\infty \frac{1-t^2}{a(1+t^2)^2- b(1+t^2)(1-t^2)} 2\,dt
\end{align}
$$
One of the factors of the denominator is $1+t^2$. Another depends on $a$ and $b$.
Now go on to partial fractions.  If $a>b>0$, you'll have two irreducible quadratic factors in the denominators, so you'll get some arctangents and maybe also some logarithms.
