# Integrating $\sqrt{x^2+a^2}$

I'm trying to integrate this function wrt $x$, substituting $x = a \tan \theta$

$$\int \sqrt{x^2+a^2} dx = a^2 \int \frac {d\theta}{\cos^3\theta} =$$

$$= a^2 \cdot \frac 12 \left( \tan\theta \sec\theta + \ln\lvert \tan\theta + \sec\theta \rvert \right) = \frac 12 \left( x \sqrt{a^2 + x^2} + a^2 \ln \left| \frac x a + \frac{\sqrt{a^2+x^2}}{a} \right| \right)$$

But WolframAlpha says it should be

$$= \frac 12 \left( x \sqrt{a^2 + x^2} + a^2 \ln \left| x + \sqrt{a^2+x^2} \right| \right)$$

What am I doing wrong?

## 2 Answers

Notice, your result is correct because adding or subtracting a constant will make no difference in the result. This can also be obtained using integration by parts

let $$I=\int \sqrt{x^2+a^2}\ dx\tag 1$$ $$I=\int \underbrace{\sqrt{x^2+a^2}}_{I}\cdot \underbrace{1}_{II}\ dx$$ using integration by parts $$I=\sqrt{x^2+a^2}\int \ dx-\int\left(\frac{d}{dx}(\sqrt{x^2+a^2})\cdot \int 1\ dx\right)\ dx$$ $$I=x\sqrt{x^2+a^2}-\int\left(\frac{2x}{2\sqrt{x^2+a^2}}\cdot x\right)\ dx$$ $$I=x\sqrt{x^2+a^2}-\int\left(\frac{x^2}{\sqrt{x^2+a^2}}\right)\ dx$$ $$I=x\sqrt{x^2+a^2}-\int\frac{(x^2+a^2)-a^2}{\sqrt{x^2+a^2}}\ dx$$ $$I=x\sqrt{x^2+a^2}-\int \sqrt{x^2+a^2}\ dx+a^2\int\frac{1}{\sqrt{x^2+a^2}}\ dx$$ from (1) $$I=x\sqrt{x^2+a^2}-I+a^2\int\frac{1}{\sqrt{x^2+a^2}}\ dx$$ $$I=\frac{1}{2}\left(x\sqrt{x^2+a^2}+a^2\int\frac{1}{\sqrt{x^2+a^2}}\ dx\right)\tag 2$$

Now, let $x=a\tan \theta\implies dx=a\sec^2\theta\ d\theta$ $$\int\frac{1}{\sqrt{x^2+a^2}}\ dx= \int\frac{1}{\sqrt{a^2\tan^2\theta+a^2}}(a\sec^2\theta \ d\theta)$$ $$=\int \sec\theta\ d\theta=\ln|\sec\theta +\tan\theta|$$

$$=\ln\left|\tan\theta+\sqrt{\tan^2\theta+1}\right|=\ln\left|x+\sqrt{x^2+a^2}\right|+c$$ setting the value in (2), we get $$I=\frac{1}{2}\left(x\sqrt{x^2+a^2}+a^2\ln\left|x+\sqrt{x^2+a^2}\right|\right)$$

$$\frac 12 \left( x \sqrt{a^2 + x^2} + a^2 \ln \left| \frac x a + \frac{\sqrt{a^2+x^2}}{a} \right| \right)\\=\frac 12 \left( x \sqrt{a^2 + x^2} + a^2 \ln \left| x + \sqrt{a^2+x^2} \right| \right)-\frac{a^2\ln|a|}{2}$$

and

$$\frac 12 \left( x \sqrt{a^2 + x^2} + a^2 \ln \left| x + \sqrt{a^2+x^2} \right| \right)$$

are different by a constant, so nothing is wrong!