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.
 A: You were right to write the expression like
$$\frac{1}{x^2+1} +\frac{2x}{x^2+1}$$

The easiest way to find the integral is to notice that
$$\frac{2x}{x^2+1} = \frac{(x^2+1)'}{x^2+1}$$
and this is a logarithmic derivative.
Also, 
$$\int \frac{dx}{x^2+1} = \arctan x + C$$
A: The way you integrated that function is wrong. And why would you use a u-substitution after you have completed the integration process? Here's what you should have gotten:
$$
\int\frac{2x+1}{x^2+1}\,dx=
\int\frac{2x}{x^2+1}\,dx+\int\frac{1}{x^2+1}\,dx=\\
\int\frac{1}{x^2+1}\frac{d}{dx}(x^2+1)\,dx+\tan^{-1}{x}\overset{u=x^2+1}=\\
\int\frac{1}{u}\,du+\tan^{-1}{x}=
\ln{|u|}+\tan^{-1}{x}=\\
\ln(x^2+1)+\tan^{-1}{x}+C.
$$
A: 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.$$
