<s>[INST] What is the integral of $\frac{2x+1}{x^2+1}$ I know the integral can be found by writing it as $$\frac{1}{x^2+1} +\frac{2x}{x^2+1}$$ This gives us an answer of $$\ln(x^2+4) +\frac{1}{2} \tan^{-1} \frac{x}{2}$$ However, when I let $x=2\tan u$, I get 
$$\frac{1}{2} \tan^{-1} \frac{x}{2} + 2\ln\left|\text{sec(tan}^{-1} \frac{x}{2})\right|$$ This can be simplified and will give the same results for large values of $x$ but not smaller values. What am I doing wrong. Sorry for the format, I am still trying to figure out Latex.
 [/INST] You can use a trigonometric substitution if you want, although separating the integrand is probably easier. Since $\tan^2 u+1 = \sec^2 u$, though, try $x = \tan u$. Then $dx = \sec^2u\,du$, and the integral becomes
$$\int \frac{2x+1}{x^2+1}\,dx = \int\frac{2\tan u+1}{\sec^2 u}\cdot \sec^2 u\,du
= \int (2\tan u+1)\,du
= u - \ln|\cos u|+C.
$$
Resubstituting gives
$$\tan^{-1}x - \ln|\cos(\tan^{-1}x)|+C = \tan^{-1}x + \ln\sqrt{x^2+1}+C.$$
</s>