$\int_{a}^{b}$ $\frac{1}{\sqrt{(x-a)(b-x)}}dx$ using substitution $x=a\cos^2u + b\sin^2u$ I am preparing for my exam by practicing some tasks. I know a way to solve the follwoing integral, but I want to solve it with the hint, my teacher gave us:

Show that the improper integral $$\displaystyle\int_{a}^{b} \frac{1}{\sqrt{(x-a)(b-x)}}dx$$ exists and evaluate the integral. Hint: Use the substitution $x= a\cos^2u + b\sin^2 u$

Well I saw a similar post, but the answers didn't really help me since I am stuck nevertheless. This is what I have.
Let $x= a\cos^2u + b\sin^2u=a(1-y)+by$ Thus we get $u(x)=\arcsin (\frac{x-a}{b-a})$ and $y(b)=1$ and $y(a)=-1$ and dy=y(b-a) and therefore we get $$\displaystyle\int_{-1}^{1} \frac{1}{\sqrt{y(1-y)}}dy$$ which would be $$\displaystyle\int_{\frac{-\pi}{2}}^{\frac{\pi}{2}}\frac{1}{\sin u \cos u}du$$. Since this is exact the same as $$\displaystyle\int_{\frac{-\pi}{2}}^{\frac{\pi}{2}}\frac{\sec^2 u}{ \tan u}du$$ and we get $$\ln(|\tan(\frac{\pi}{2})|)-\ln(|\tan(\frac{-\pi}{2})|)$$. But this can't true be since both parts are not defined.
But I know the result must be $\pi$. So where is my mistake? Is there anyone who could help me out? I would be evry grateful.
 A: It looks like there are a few issues: First, the integral in $y$ should be taken over $(0, 1)$, not $(-1, 1)$; n.b. the integrand isn't real for $y < 0$. Second, the change of variables from $y$ to $u$ seems to omit the factor $y'(u) = 2 \sin u \cos u$ required by substitution.
Applying the prescribed substitution, $$x = a \cos^2 u + b \sin^2 u, \qquad dx = 2 (b - a) \sin u \cos u$$ (where implicitly we take $0 \leq u \leq \frac{\pi}{2}$), transforms the integral to
$$2 (b - a)\int_0^{\frac{\pi}{2}} \frac{\sin u \cos u\,du}{\sqrt{[(a \cos^2 u + b \sin^2 u) - a][b - (a \cos^2 u + b \sin^2 u)]}} .$$ The first factor in the radical is
$$(a \cos^2 u + b \sin^2 u) - a = (b - a) \sin^2 u ,$$
and the second term simplifies analogously.

So, the radical expression simplifies to $\sqrt{(b - a)^2 \sin^2 u \cos^2 u} = |(b - a) \sin u \cos u|$. Since $\sin u, \cos u$ are nonnegative, provided that $b > a$ our integral simplifies to $$2 \int_0^\frac{\pi}{2} du.$$

A: Alternatively, rescale the variable with $t=\frac{x-a}{b-a}\in [0,1]$
$$\int  \frac{1}{\sqrt{(x-a)(b-x)}}dx = \int \frac1{\sqrt{t(1-t)}}dt=2\sin^{-1}\sqrt{t}+C$$
A: For $b>a$, $$
\begin{aligned}
\int \frac{1}{\sqrt{(x-a)(b-x)}} d x &=2 \int \frac{1}{\sqrt{b-x}} d(\sqrt{x-a}) \\
&=2 \int \frac{d (\sqrt{x-a})}{\sqrt{(\sqrt{b-a})^{2}-(\sqrt{x-a})^{2}}} \\
&=2 \arcsin \sqrt{\frac{x-a}{b-a}}
\end{aligned}
$$
