Integrating $\int \sqrt{a^2+x^2} \ \mathrm{d} x$ with trig. substitution I am trying to come up with all the formulas I have myself and I stumbled upon a roadblock again.
Integrating $\int \sqrt{a^2+x^2} \ \mathrm{d} x$ with Trig Substitution.
So I imagined a triangle where the hypotenuse is $1$, $\sin(y) = x$ opposite over hypotenuse and $\cos(y) = a$ adjacent over hypotenuse.
Then $dx = \cos(y)dy$ and factoring out the a out of the square root,
I get $ \int a $ $\sqrt{1+\frac{x^2}{a^2}} \ \mathrm{d} x$ or $ \int  \sqrt{1+\tan y^2}\cos y^2 \ \mathrm{d} y$
which I could simplify to $\int \cos y \ \mathrm{d} y$. This gives me the wrong answer.
Can you pinpoint or hint at where I am going wrong with my substitution once more?
Apologies, I appreciate it.
 A: In the integral $$\int\sqrt{a^2+x^2} dx $$ $a$ is supposed to be a constant, and you can’t just make it dependent on the variable of integration, by saying $a=\cos y$. The straightforward approach would be to substitute $x=a\tan y \implies dx=a\sec^2y dy$ To get$$\int a^2\sec^3y\  dy$$
A: I will not the give he same answer as others   but if you cannot do these integrals despite many tries, this is a sure shot way to get correct answers.
Substitute $x  = ai\sin(y)⟹y= \arcsin(\frac{x}{ai})$
$dx = ai\cos(y)dy$
$$I = \int \sqrt{a^2 +(i a \sin y)^2} \cdot ai\cos(y) dy$$
$$I = \int \sqrt{a^2 - a^2\sin^2y} \cdot ai\cos(y) dy$$
$$I = a^2i\int \cos(y) \cdot  \cos(y) dy$$
$$I = \frac{a^2i}{2} \Biggr(y + \cos y \sin y \Biggr)$$
$$I = \frac{a^2i}{2} \Biggr( \arcsin\biggr(\frac{x}{ai}\biggr) +  \sqrt{1+\frac{x^2}{a^2}}\cdot\biggr(\frac{x}{ai}\biggr)\Biggr)$$
Use $\arcsin(x) = -i\ln|\sqrt{1-x^2} + ix|$ to get the final answer,
A: Let $x=a\tan\theta\implies dx=a\sec^2\theta\ d\theta$
$$\int \sqrt{a^2+x^2}dx=\int \sqrt{a^2+a^2\tan^2\theta}\ a\sec^2\theta \ d\theta$$
$$=\int a\sec\theta\ a \sec^2\theta \ d\theta$$
$$=a^2\int \sec^3\theta \ d\theta$$
Using integration by parts
$$=a^2\left(\frac{1}{2}\sec\theta \tan\theta+\frac12\ln|\sec\theta+\tan\theta|\right)+C$$
substituting back to $x$,
$$=\frac{1}{2}\left(x\sqrt{a^2+x^2}+a^2\ln|x+\sqrt{a^2+x^2}|\right)+C$$
