Prove $\int_a^b \frac{1}{x}\sqrt{-(x-a)(x-b)}dx = (\frac{a+b}{2}-\sqrt{ab})\pi$ Does anyone know how to solve $$\int_a^b \frac{1}{x}\sqrt{-(x-a)(x-b)}dx$$
After trying Wolfram Alpha, I conclude that it possibly equals $(\frac{a+b}{2}-\sqrt{ab})\pi = \frac{(\sqrt{a}-\sqrt{b})^2}{2}\pi$.
The book I am reading says one can use residue theorem to quickly obtain the result, but the details are not written and I cannot figure out the solution.
P.S. One can prove from this integral that arithmetic mean $\geq$ geometric mean.
 A: Strip units under the radical. $x-a=(b-a)t$
$$I=\int_a^b\frac1x\sqrt{(x-a)(b-x)}dx=(b-a)^2\int_0^1\frac{\sqrt{t(1-t)}}{a+(b-a)t}dt$$
Then a trig substitution to eliminate the radical. $t=\sin^2\theta$
$$I=2(b-a)^2\int_9^{\pi/2}\frac{\sin^2\theta\cos^2\theta}{a+(b-a)\sin^2\theta}d\theta$$
Then an inverse trig substitution, to reduce the integrand to a rational function, $u=\tan\theta$
$$\begin{align}I&=2(b-a)^2\int_0^{\infty}\frac{u^2}{(1+u^2)^2(a+bu^2)}du\\
&=2\int_0^{\infty}\left(\frac{b-a}{(1+u^2)^2}+\frac a{1+u^2}-\frac{ab}{a+bu^2}\right)du\end{align}$$
If we let $u=\tan\theta$ again we get
$$\begin{align}2\int_0^{\infty}\left(\frac{b-a}{(1+u^2)^2}+\frac a{1+u^2}\right)du&=2\int_0^{\pi/2}\left((b-a)\cos^2\theta+a\right)d\theta\\
&=2\frac{\pi}2\left(\frac12(b-a)+a\right)=\frac{\pi}2(b+a)\end{align}$$
Because the average value of $\cos^2\theta$ is $1/2$, the average value of $1$ is $1$ and the length of the interval is $\pi/2$. Then in the last integral we can let $\sqrt b\,u=\sqrt a\,\tan\phi$ so
$$-2ab\int_0^{\infty}\frac{du}{a+bu^2}=-2\sqrt{ab}\int_0^{\pi/2}d\phi=-\pi\sqrt{ab}$$
Adding up, we get
$$I=\int_a^b\frac1x\sqrt{(x-a)(b-x)}dx=\pi\left(\frac{b+a}2-\sqrt{ab}\right)$$
But did you want the residue theorem?
EDIT: Since the answer was in the affirmative, we note first that there is a problem that the integrand approaches $1$ as $|x|\rightarrow\infty$. Thus the closure of the contour is problematic. Accordingly I make the substitution $t=1/x$:
$$\int_a^b\frac{\sqrt{(x-a)(b-x)}}xdx=\int_{1/b}^{1/a}\frac{\sqrt{(1-at)(bt-1)}}{t^2}dt$$
Now we can do some contour integratin'! Consider the contour $C$ illustrated below that starts on the right edge of a circle of radius $r$ centered at $z=1/a$, goes due east along contour $C_1$ until it hits a circle of radius $R$ centered at $z=0$, follows that circle counterclockwise along contour $C_2$ until it's back at the real axis again, goes back west along contour $C_3$ until it again encounters the circle of radius $r$ centered at $z=1/a$, follow that circle clockwise along contour $C_4$ until it hits the real axis west of $z=1/a$, follows the real axis west along contour $C_5$ until it encounters the circle of radius $r$ centered at $z=1/b$, follows that circle clockwise along contour $C_6$ until it hits the real axis east of $z=1/b$, goes east along contour $C_7$ until it encounters the circle of radius $r$ centered at $z=1/a$ and finally follows that circle clockwise along contour $C_8$until it arrives back at its starting point.

Contours $C_4$, $C_6$, and $C_8$ contribute nothing to the integeral as $r\rightarrow0$ because the magnitudes of the integrand are bounded there and the length of the contours approaches zero. Contours $C_1$ and $C_3$ have the same phase because we take the branch cut from $z=1/b$ to $z=1/a$ along the real axis. They are traversed in opposite directions, however, so the cancel. Contour $C_7$ is the integral we want and this time contour $C_5$ has opposite phase and direction so it has the same magnitude and sign as contour $C_7$. Contour $C_2$ is the formerly problematic closure
$$\begin{align}\int_{C_2}\frac{\sqrt{(1-az)(bz-1)}}{z^2}dz&=\int_0^{2\pi}\frac{\sqrt{(1-aRe^{i\theta})(bRe^{i\theta}-1)}}{R^2e^{2i\theta}}iRe^{i\theta}d\theta\\
&=\int_0^{2\pi}i\sqrt{ab}e^{-\pi i/2}\left(1+O(1/R)\right)d\theta\\
&=2\pi\sqrt{ab}+O(1/R)\rightarrow2\pi\sqrt{ab}\end{align}$$
As $R\rightarrow\infty$ We thus have the results
$$2\int_a^b\frac{\sqrt{(x-a)(b-x)}}xdx+2\pi\sqrt{ab}=2\pi i\sum(\text{residues})$$
The only pole within the contour is at $z=0$ and it's a second-order pole, so
$$\begin{align}\sum(\text{residues})&=\left.\frac d{dz}\left(z^2\frac{\sqrt{(1-az)(bz-1)}}{z^2}\right)\right|_{z=0}\\
&=\left.-\frac a2\frac{\sqrt{bz-1}}{\sqrt{1-az}}+\frac b2\frac{\sqrt{}1-az}{\sqrt{bz-1}}\right|_{z=0}\end{align}$$
Now, at this pole the phase of $1-az$ is zero but the phase of $bz-1$ is $\pi$ so $\sqrt{bz-1}=e^{\pi i/2}$ and
$$\sum(\text{residues})=-\frac a2e^{\pi i/2}+\frac b2e^{-\pi i/2}=-\frac i2(a+b)$$
So we are done:
$$\int_a^b\frac{\sqrt{(x-a)(b-x)}}xdx=-\pi\sqrt{ab}+\frac{\pi}2(a+b)$$
Was that really easier?
EDIT: Of course after typesetting all this stuff and drawing the figure and submitting it I could see how to do the contour integral without any substitutions. The contour is the same as in my illustration except that the point $z=1/b$ becomes $z=a$ and the point $z=1/a$ becomes $z=b$. The 'problematic' closure contour $C_2$ is handled by observing that
$$\begin{align}\sqrt{Re^{i\theta}-a}&=\sqrt Re^{i\theta/2}\sqrt{1-\frac aRe^{-i\theta}}\\
&=\sqrt Re^{i\theta/2}\left\{1-\frac a{2R}e^{-i\theta}-\frac{\frac{a^2}{4R^2}e^{-2i\theta}}{\sqrt{1-\frac aRe^{-i\theta}}+1-\frac a{2R}e^{-i\theta}}\right\}\end{align}$$
And
$$\begin{align}\sqrt{b-Re^{i\theta}}&=\sqrt Re^{i\theta/2}e^{-\pi i/2}\sqrt{1-\frac bRe^{-i\theta}}\\
&=\sqrt Re^{i\theta/2}e^{-\pi i/2}\left\{1-\frac b{2R}e^{-i\theta}-\frac{\frac{b^2}{4R^2}e^{-2i\theta}}{\sqrt{1-\frac bRe^{-i\theta}}+1-\frac b{2R}e^{-i\theta}}\right\}\end{align}$$
Then after multiplying everything out and noting also that
$$\int_0^{2\pi}Re^{i\theta}d\theta=\int_0^{2\pi}R^{-1}e^{-i\theta}d\theta=0$$
We get useful stuff from contour $C_2$ after all.
A: Let $\sin^2t = \frac{x-a}{b-a}$
\begin{align}
&\int_a^b \frac{1}{x}\sqrt{(a-x)(x-b)}dx \\
=& \int_0^{\pi/2} \frac{{(b-a)^2}(1-\cos^2 2t)}{(a+b)-(b-a)\cos 2t}\>dt\\
=&\int_0^{\pi/2} \left[(a+b) + (b-a)\cos2t - \frac{4ab}{(a+b)-(b-a)\cos 2t} \right]dt\\
=& \frac{(a+b)\pi}2 - \sqrt{ab}\pi \\
\end{align}
where $\int_0^{\pi/2} \frac{du}{p-q\cos2t}=\frac{\pi}{2\sqrt{p^2-q^2}}$ is used.
A: Let $x=a\cos^2 t+b \sin^2 t  \implies dx=(b-a) \sin 2t dt$
Then $$I=2\int_{0}^{\pi/2} \frac{(b-a)^2 \sin^2 t \cos^2 tdt}{a \cos^2 t+b \sin^2t}= 2 (b-a)^2 \int_{0}^{\pi/2}\frac{ \sin^2 t ~dt}{a+b\tan^2 t}$$
Let $\tan t=u$, then
$$I=2\int_{0}^{\infty} \frac{u^2 du}{(1+u^2)^2(a+bu^2)}=2\int_{0}^{\infty} du \left(\frac{b-a}{(1+u^2)^2}+\frac{a}{1+u^2}-\frac{ab}{a+bu^2}\right)$$
$$\implies I=\left. (b-a)\left(\frac{u}{1+u^2}+\tan^{-1}u\right)+2a \tan^{-1}u -2\sqrt{ab} ~\tan^{-1}\frac{u\sqrt{b}}{\sqrt{a}} \right|_{0}^{\infty}=\left(\frac{a+b}{2}-\sqrt{ab} \right) \pi $$
I will get back.
A: Noticing that $(x-a)(b-x)=\left(\frac{b-a}{2}\right)^2-\left(x-\frac{a+b}{2}\right)^2$, we let $x-\frac{a+b}{2}=\frac{b-a}{2} \sin \theta$ and transforms the integral into $$
\begin{aligned}I&=\left(\frac{b-a}{2}\right)^2 \int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} \frac{\cos ^2 \theta}{\frac{b-a}{2} \sin \theta+\frac{a+b}{2}} d \theta \\ &=h^2 \int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} \frac{\cos ^2 \theta}{h \sin \theta+k} d \theta\end{aligned}
$$
where $h=\frac{b-a}{2}$ and $k=\frac{a+b}{2}$.
$$
\begin{aligned}
\int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} \frac{\cos ^2 \theta}{h \sin \theta+k} d \theta =& \int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} \frac{1-\sin ^2 \theta}{h \sin \theta+k} d \theta \\
=& \int_{-\frac{\pi}{2}}^{\frac{\pi}{2}}\left(-\frac{\sin \theta}{h}+\frac{k}{h^2}+\frac{1-\frac{k^2}{h^2}}{h \sin \theta+k}\right) d \theta\\
=& {\left[\frac{\cos \theta}{h}+\frac{k}{h^2} \theta\right]_{-\frac{\pi}{2}}^{\frac{\pi}{2}}+\frac{h^2-k^2}{h^2} \int_{-\frac{\pi}{2}}^{\frac{\pi}{2}} \frac{d \theta}{h \sin \theta+k} } \quad (*)\\=& \frac{k \pi}{h^2}-\frac{k^2-h^2}{h^2} \cdot\frac{\pi}{\sqrt{k^2-h^2}}\\=&\frac{\pi}{h^2}\left(k-\sqrt{k^2-h^2}\right)
\end{aligned}
$$
We now conclude that
$$\boxed{ \int_a^b \frac{1}{x} \sqrt{(x-a)(b-x)} d x=\left(\frac{a+b}{2}-\sqrt{a b}\right) \pi}$$
Note:
Please refer to the post for (*).
