Evaluating $\int \sqrt{\frac{x^2+1}{x^2(1-x^2)}}dx$

calculusindefinite-integralsintegration

Today I came across the following integral
$$\int \sqrt{\frac{x^2+1}{x^2(1-x^2)}}dx$$


Here's my work:
$$\begin{align}\int \sqrt{\frac{x^2+1}{x^2(1-x^2)}}dx& = \int\frac{1}{x} \sqrt{\frac{1+x^2}{1-x^2}}\ dx \\ & = -\int \sqrt{\frac{1+\cos(2\theta)}{1 – \cos(2\theta)}} \tan(2\theta) \ d\theta\tag{$*$}\\& = -\int \sqrt{\frac{2\cos^2(\theta)}{2\sin^2(\theta)}}\cdot \frac{\sin(2\theta)}{\cos(2\theta)} \ d\theta\\& = – \int\frac{\cos(\theta)}{\sin(\theta)}\cdot \frac{2\sin(\theta)\cos(\theta)}{\cos^2\theta – \sin^2\theta}\ d\theta\\& = – \int \frac{(\cos^2\theta + \sin^2\theta) + (\cos^2\theta – \sin^2\theta)}{\cos^2\theta – \sin^2\theta}\ d\theta\\& = – \int \sec(2\theta) + 1 \ d\theta\tag{1}\\& =-\frac{1}2 \ln|\sec(2\theta) + \tan(2\theta)| + \theta + C\tag{2}\\& = – \frac{1}{2} \ln\left|\sec(\cos^{-1}(x^2)) + \tan(\cos^{-1}(x^2))\right| + \frac12 \cos^{-1}(x^2) + C\\& = – \frac12\ln\left|\frac1{x^2} + \frac{\sqrt{1 – x^4}}{x^2}\right| + \frac12 \cos^{-1}(x^2) + C\\& = – \frac12\ln\left|\frac{1 + \sqrt{1 – x^4}}{x^2}\right| + \frac12 \cos^{-1}(x^2) + C\end{align}$$


$(*)$ Here I've made a substitution $x^2 = \cos(2\theta)$ so that $\dfrac{dx}{x} = – \tan(2\theta)\ d\theta$.


But this answer seems to be wrong! I differentiated my answer but didn't get the original integrand. Wolframalpha results this expression and I'm not sure about it.

I'm just unable to figure out what's actually wrong with my method.

Edit:

With Bob Dobbs's comment, I got that I did wrong moving from step $(1)$ to step $(2)$.

Best Answer

The back trigonometric substitution could be problematic. To avoid it, integrate instead as follows

$$\int \sqrt{\frac{x^2+1}{x^2(1-x^2)}}dx= \int \frac x{\sqrt{1-x^4}}dx+\int \frac1{\sqrt{x^2(1-x^4})}dx $$ where \begin{align} &\int \frac x{\sqrt{1-x^4}}dx=\frac12\int \frac {d(x^2)}{\sqrt{1-x^4}}=\frac12\sin^{-1}x^2\\ &\int \frac 1{\sqrt{x^2(1-x^4})}dx=\frac12\int \frac {d(\sqrt{1-x^4})}{(1-x^4)-1}=-\frac12\tanh^{-1} \sqrt{1-x^4} \end{align}