Integrating $\int\frac{dx}{(x-a)(x-b)}$ by means of a trigonometric substitution I've been trying to integrate
$$\int\frac{dx}{(x-a)(x-b)}$$
By using the substitution
$$x=a \cos^2  \theta + b \sin^2 \theta$$
The only problem here is I arrived at the result
$$\frac{2}{a-b} \ln |\csc 2\theta - \cot 2\theta|+c$$
and I having trouble on how to substitute from $\theta$ to $x$.
 A: You can use a Weierstrass substitution: $$t:=\tan\theta\implies\csc 2\theta-\cot 2\theta=\frac{1+t^2}{2t}-\frac{1-t^2}{2t}=t=\sqrt{\frac{x-a}{b-x}}$$since$$x-a=(b-a)\sin^2\theta,\,b-x=(b-a)\cos^2\theta.$$
A: This is not an answer, but I am posting an alternate method for fun.  This algebraic approach should be simpler than the trigonometric substitution, and thus it's useful in exams/tests in which time is limited.
Observe that the integrand is a rational function which can be decomposed into two simple partial-fractions.
$$\frac{1}{(x-a)(x-b)} = \frac{1}{a-b} \left[ \frac{1}{x-a} - \frac{1}{x-b}\right]$$
This gives
\begin{aligned}
\int\frac{dx}{(x-a)(x-b)} =& \frac{1}{a-b} \left[ \int\frac{dx}{x-a} - \int\frac{dx}{x-b}\right] \\
=& \frac{1}{a-b} (\ln|x-a| - \ln|x-b|) + C.
\end{aligned}
A: As stated in the comments, we assume $a$ and $b$ are positive real numbers. In this case, without loss of generality, we may assume $a\leq b$. This gives $$x=a\cos^2(\theta)+b\sin^2(\theta)=a\cos^2\theta+a\sin^2\theta+(b-a)\sin^2\theta=a+(b-a)\sin^2\theta.$$This allows us to solve for $\theta$ so that we find $$\theta=\arcsin\sqrt{\frac{x-a}{b-a}\,}.$$Plugging into $\csc(2\theta)$ and $\cot(2\theta)$, applying double-angle formulas, and reducing the trigonometry (first using algebra to reduce to $\tan\theta$ and then using triangles), we find that $$\int\frac{1}{(x-a)(x-b)}\,dx = \frac{1}{a-b}\left(\ln|x-a|-\ln|x-b|\right)+C.$$
A: Take the middle of the two roots $x_0=\dfrac{a+b}2$ and make a substitution $t=x-x_0$
Then $\displaystyle\int\dfrac{\mathop{dx}}{(x-a)(x-b)}=\int\dfrac{\mathop{dt}}{\left(t^2-(\frac{a-b}2)^2\right)}=-\dfrac 2{a-b}\tanh^{-1}\left(\dfrac{2t}{a-b}\right)+C\quad$ for $x\in[a,b]$
Note: for $x$ outside $[a,b]$ use the form in $\operatorname{cotanh}^{-1}$ instead.

Rem: using the formula $\tanh^{-1}(x)=\dfrac 12\ln\left(\dfrac{1+x}{1-x}\right)$, I let you convince yourself it is the same as the answer given by GNU or Clayton.
In a doubt, you can look at this post for a similar approach, where I calculated in detail the equality with other forms of the result.
Integral of product of two inverse polynomials
