Integrating With Trig Subsitution Can someone please explain how to calculate the integral of
$\frac{\sqrt{1 + x^2}}{x}$ using trig substitution?
 A: In all the following, I intentionnally forget the constant to add to every primitive, in order to simplify the notations. All equalities with primitives are to be understood "up to a constant".
Using trigonometric functions, and substitution $x=\tan u$ (then $\mathrm{d}x=(1+\tan^2u)\,\mathrm{d}u = \frac{\mathrm{d}u}{cos^2u}$):
$$\int \frac{\sqrt{1+x^2}}{x} \mathrm{d}x=\int \frac{\sqrt{1+\tan^2 u}}{\tan u} \frac{1}{\cos^2u}\mathrm{d}x=\int \frac{1}{|\cos u| \tan u} \frac{1}{\cos^2u} \mathrm{d}u$$
If $\cos u > 0$,
$$\int \frac{\sqrt{1+x^2}}{x} \mathrm{d}x=\int \frac{1}{\sin u\cos^2u} \mathrm{d}u$$
Then 
$$\frac{1}{\sin u\cos^2u}=\frac{1}{\cos^2u}\left(\frac{1}{\sin u} - \sin u + \sin u\right) = \frac{1}{\cos^2u}\left( \frac{1-\sin^2 u}{\sin u}+\sin u\right)$$
$$=\frac 1 {\sin u} + \frac{\sin u}{\cos^2 u}$$
And (see here)
$$\int \frac{1}{\sin u} \mathrm{d}u=\log \left|\tan \frac u 2\right|$$
$$\int \frac{\sin u}{\cos^2 u} \mathrm{d}u = \frac 1 {\cos u}$$
So 
$$\int \frac{\sqrt{1+x^2}}{x} \mathrm{d}x=\frac 1 {\cos u} +\log \left|\tan \frac u 2\right| = \frac 1 {\cos (\arctan x)} +\log \left|\tan \frac {\arctan x} 2\right| $$
Now $\frac{1}{\cos^2 u}=1+\tan^2 u$ thus $\frac 1{\cos (\arctan x)} = \sqrt{1+x^2}$,
$$\int \frac{\sqrt{1+x^2}}{x} \mathrm{d}x = \sqrt{1+x^2} +\log \left|\tan \frac {\arctan x} 2\right| $$
Also, notice we have always $\cos u = \cos (\arctan x) > 0$ since $\arctan x \in ]-\pi/2, +\pi/2[$. Our assumption above was not too restrictive :-)

There is further simplification, with $\tan \frac{\arctan x}{2}$.
The idea is to write $\tan \frac{\theta}2$ as a function of $\tan \theta$, that is, reversing the usual formula $\tan \theta = \frac{2t}{1-t^2}$ where $t=\tan \frac{ \theta }2$.
That is, we want to solve
$$(1-t^2) \tan \theta -2t = 0$$
$$(\tan \theta) t^2 + 2t - \tan \theta = 0$$
It's a quadratic equation with $\Delta = 4(1+\tan^2\theta$), so the solutions are
$$t = \frac{-1 \pm \sqrt{1+\tan^2 \theta}}{\tan \theta}$$
Notice that $t = \tan \frac{\theta}{2}$ has the same sign than $\tan \theta$ for $\theta \in ]-\pi/2, \pi/2[$, so the sign in $\pm$ is actually a $+$.
$$\tan \frac{\theta}{2}=\frac{\sqrt{1+\tan^2 \theta}-1}{\tan \theta}$$
And
$$\tan \frac{\arctan x}{2}=\frac{\sqrt{1+x^2}-1}{x}$$
Therefore, we have
$$\int \frac{\sqrt{1+x^2}}{x} \mathrm{d}x = \sqrt{1+x^2} +\log \left|\frac{\sqrt{1+x^2}-1}{x}\right|=\sqrt{1+x^2} +\log (\sqrt{1+x^2}-1) - \log |x| $$

The answer can be written slightly differently:
$$\sqrt{1+x^2} -\log (\sqrt{1+x^2}+1) + \log |x|$$
It's enough to check that
$$\frac{(\sqrt{1+x^2}+1)(\sqrt{1+x^2}-1)}{|x|^2}=\frac{1+x^2-1}{x^2}=1$$
Thus, taking logarithms,
$$\log (\sqrt{1+x^2}+1) + \log (\sqrt{1+x^2}-1) - 2\log |x| =  0$$
$$\log (\sqrt{1+x^2}-1) - \log |x| = -\log (\sqrt{1+x^2}+1) + \log |x|$$

There is still place for a bit of simplification:
$$\log (\sqrt{1+x^2}+1) - \log |x|=\log \frac{\sqrt{1+x^2}+1}{|x|}=\log \left(\sqrt{1+\frac{1}{|x|^2}}+\frac{1}{|x|}\right)$$
You may recognize $\arg\sinh t = \log (t + \sqrt{1+t^2})$, so
$$\log (\sqrt{1+x^2}+1) - \log |x|=\arg \sinh \frac{1}{|x|}$$
Thus, as a final step, we can write
$$\int \frac{\sqrt{1+x^2}}{x} \mathrm{d}x = \sqrt{1+x^2}-\arg \sinh \frac{1}{|x|}$$

Another solution, using hyperbolic functions, with substitution $x=\sinh u$ (and $\mathrm{d}x=\cosh u \,\mathrm{d}u$), using the fact that $\cosh^2 u - \sinh^2 u = 1$:
$$\int \frac{\sqrt{1+x^2}}{x} \mathrm{d}x = \int \frac{\cosh u}{\sinh u} \cosh u \,\mathrm{d}u= \int \frac{1+\sinh^2u}{\sinh u} \mathrm{d}u$$
$$=\int \left(\frac{1}{\sinh u}+\sinh u\right) \mathrm{d}u$$
And, with the usual $\int \frac 1 {\sinh u} \,\mathrm{d}u = \frac 1 2\log|\tanh \frac u 2|$,
$$\int \frac{\sqrt{1+x^2}}{x} \mathrm{d}x=\frac 1 2\log\left|\tanh \frac u 2\right| + \cosh u = \frac 1 2\log\left|\tanh \frac {\arg \sinh x} 2\right| + \cosh (\arg \sinh x)$$
$$=\sqrt{1+x^2} + \frac 1 2\log\left|\tanh \frac {\arg \sinh x} 2\right|$$
Like with the first solution, it would be possible to simplify further.
