<s>[INST] Can trigonometric substitution be used to solve this integral? The integral in question is $$\int \frac{x+1}{9x^2+6x+5}dx.$$ I first completed the square in the denominator giving $(3x+1)^2+4$ and proceeded to perform a $u$-substitution with $u = 3x+1$, $du=3~dx$, and $x=(u-1)/3$. After simplifying, I was left with $$\frac{1}{9}\int\frac{u+2}{u^2+4}du.$$ It is at this point I used trigonometric substitution with $u = 2\tan\theta$ and $du = 2\sec^2\theta~d\theta$ (I'm aware the integral can be written as $\frac 1 9\int\frac{u}{u^2+4}du+\frac 1 9\int\frac{2}{u^2+4}du$ and solved this way). After performing the trig substitution, I was left with $$\frac 1 9\int(\tan\theta + 1)~d\theta = \frac 1 9 \ln|\sec\theta|+\frac 1 9 \theta + C.$$ Rewriting everything in terms of $x$ gave me $$\frac 1 9\ln\left(\frac{(3x+1)^2+4}{2}\right)+\frac{1}{9}\tan^{-1}\left(\frac 1 2(3x+1)\right)+ C,$$ which is incorrect. The correct answer is $$\frac{1}{18}\ln\left(9x^2+6x+5\right)+\frac{1}{9}\tan^{-1}\left(\frac 1 2(3x+1)\right)+ C.$$ What went wrong with my trig substitution?
 [/INST] $$\begin{align*}
\int \frac{x+1}{9x^2+6x+5}dx
&=\int\frac{x+1}{(3x+1)^2+2^2}dx\\ (u = 3x+1)\\
& = \frac{1}{9}\int\frac{u+2}{u^2+2^2}du\\ (u = 2\tan\theta)\\
&=\frac{1}{9}\int\frac{(2\tan\theta+2)(2\sec^2\theta)}{2^2(1+\tan^2\theta)}d\theta\\
&=\frac{1}{9}\int(\tan\theta+1)d\theta\\
& = \frac{1}{9}\ln{|\sec\theta|} + \frac{1}{9}\theta + C_0
\end{align*}$$
Now, $|x| = \sqrt{x^2}$
$\implies \ln|\sec\theta| = \ln{(\sqrt{\sec^2{\theta}})} = \frac{1}{2}\ln{\sec^2{\theta}} = \frac{1}{2}\ln{(1+\tan^2{\theta})}$
Which for the above:
$$\begin{align*}
\frac{1}{9}\ln{|\sec\theta|} + \frac{1}{9}\theta + C_0
& = \frac{1}{9}\times\frac{1}{2}\ln{(1+\tan^2{\theta})}+ \frac{1}{9}\theta + C_0\\
& = \frac{1}{9}\times\frac{1}{2}\ln\left(1+\left(\frac{3x+1}{2}\right)^2\right) + \tan^{-1}\left(\frac{3x+1}{2}\right)+C_0\\
& = \frac 1{18}\ln(9x^2 + 6x +5) + \tan^{-1}\left(\frac{3x+1}{2}\right)+(C_0 - \frac 1{18}\ln(4))\\
& = \frac 1{18}\ln(9x^2 + 6x +5) + \tan^{-1}\left(\frac{3x+1}{2}\right)+C
\end{align*}$$
</s>