I'm attempting to integrate the following using trig substituion: $$\int \frac{\sqrt{1+x^2}}{x}dx$$ and I am getting the result: $$-\ln{\lvert \frac{ \sqrt{x^2 + 1} - 1}{x} \rvert} + \sqrt{x^2 + 1} + C$$
However, my answer guide and this yahoo answer both indicate that the $-\ln$ should now be positive, I can't seem to figure out why (although I'm sure it's painfully simple). I thought it might be related to the fact that $\ln{\frac1x} = -\ln{x}$ but I can't wrap my head around it.
I've provided my steps below:
I start with $x=\tan\theta$ and $dx=\sec^2\theta d\theta$
Which brings me to $$\int \frac{\sqrt{1+\tan^2\theta}}{\tan\theta}\sec^2\theta d\theta$$
and then: $$\int \frac{\sec^2\theta(\sec\theta)}{\tan\theta} d\theta$$
.... next I substitute $(1+\tan^2\theta)$ for $\sec^2\theta$ and multiply by the $\sec\theta$ already in the numerator, giving me: $$\int \frac{\sec\theta+\sec\theta\tan^2\theta}{\tan\theta}d\theta$$
I separate this out into two separate fractions, canceling one power of $\tan\theta$ in its respective fraction:
$$\int \frac{\sec\theta}{\tan\theta} + \sec\theta\tan\theta d\theta$$
This can be split into two integrals, and the left side can be rewritten as $\csc\theta$:
$$\int \csc\theta d\theta + \int \sec\theta\tan\theta d\theta$$
Which using known integrals can be determined to be:
$$-\ln{\lvert \csc\theta - \cot\theta \rvert} + \sec\theta + C$$
Creating a triangle to determine $\csc\theta$, $\cot\theta$, and $\sec\theta$ in terms of x yields me:
$$-\ln{\lvert \frac{ \sqrt{x^2 + 1} - 1}{x} \rvert} + \sqrt{x^2 + 1} + C$$
Edit: So it turns out I had the formula for $\int\csc\theta d\theta$ wrong. As user84413 pointed out in the comments, the formula is:
$$\int\csc\theta d\theta=\ln|\csc\theta-\cot\theta|+C=-\ln|\csc\theta+\cot\theta|+C$$
Using this corrected formula for my second to last step, I get the correct answer.
Your Second last line is $\displaystyle - \ln\left|\csc \theta-\cot \theta\right|+\sec\theta +\mathcal{C}$
Now Using $\displaystyle \csc^2 \theta-\cot^2 \theta = 1\Rightarrow (\csc \theta -\cot \theta) = \frac{1}{\csc \theta +\cot \theta}$
So we get $\displaystyle = -\ln\left|\frac{1}{\csc \theta+\cot \theta}\right|+\sec \theta+\mathcal{C}$
So we get $\displaystyle = \ln\left|\csc \theta+\cot \theta\right|+\sec \theta+\mathcal{C}$
So $\displaystyle =\ln\left|\frac{\sqrt{1+x^2}+1}{x}\right|+\sqrt{1+x^2}+\mathcal{C}$
$\bf{Solution \; without \; Trig. \; Substution.}$
Let $$\displaystyle I = \int\frac{\sqrt{1+x^2}}{x}dx = \int\frac{1+x^2}{x\sqrt{1+x^2}}dx = \int\frac{1}{x\sqrt{1+x^2}}dx+\int\frac{x}{\sqrt{1+x^2}}dx$$
Now Let $$\displaystyle J = \int\frac{1}{x\sqrt{x^2+1}}dx\;,$$ Put $\displaystyle x = \frac{1}{t}\;,$ Then $\displaystyle dx = -\frac{1}{t^2}dt$
So $$\displaystyle J = -\int\frac{1}{\sqrt{t^2+1}}dt = -\ln\left|t+\sqrt{t^2+1}\right|+C_{1} = -\ln\left|\frac{\sqrt{x^2+1}+1}{x}\right|+\mathcal{C_{1}}$$
And Let $$\displaystyle K=\int\frac{x}{\sqrt{x^2+1}}dx\;,$$ Now put $\displaystyle x^2+1=u^2\;,$ Then $xdx = udu$
So we get $$\displaystyle K = \int\frac{u}{u}du = u+\mathcal{C_{2}} = \sqrt{x^2+1}+\mathcal{C_{2}}$$
So we get $$\displaystyle I = \int\frac{\sqrt{1+x^2}}{x}dx = -\ln\left|\frac{\sqrt{x^2+1}+1}{x}\right|+\sqrt{x^2+1}+\mathcal{C}$$