# u-sub vs trig-sub are giving different answers for $\int\frac{x+4}{x^2+2x+5}dx$

When I complete the square in the denominator and solve using u-sub, I can get the right answer:

$$\int\frac{x+4}{x^2+2x+5}dx$$ $$\int\frac{x+4}{x^2+2x+1+4}dx$$ $$\int\frac{(x+1)+4}{(x+1)^2+4}dx$$ $$u=x+1$$ $$\int\frac{u+3}{u^2+4}du$$ $$I_1=\int\frac{u}{u^2+4}du+I_2=\int\frac{3}{u^2+4}du$$ $$I_1=(w=u^2+4, dw=2udu)$$ $$I_1=\frac{1}{2}\int\frac{dw}{w}$$ $$w = u^2+4,$$

$$w = (x+1)^2+4,$$ so: $$I_1=\frac{1}{2}\ln|x^2+2x+5|$$ $$I_2=3\int\frac{1}{u^2+4}du$$ $$u = 2\tan\theta$$

$$du = 2\sec^2\theta d\theta$$ $$I_2=3\int\frac{2\sec^2\theta}{(2\tan\theta)^2+4}d\theta$$ $$I_2=3\int\frac{2\sec^2\theta}{4\tan^2\theta+4}d\theta$$ $$I_2=3\int\frac{2\sec^2\theta}{4\sec^2\theta}d\theta$$ $$I_2=\frac{3}{2}\int d\theta$$ $$I_2=\frac{3\theta}{2}$$

At this point, I have to turn the integral back into terms of x, so I made the right triangle like normal: Now solving the integrals:

$$\frac{1}{2}\ln|x^2+2x+5|+\frac{3\theta}{2}$$ $$\frac{1}{2}\ln|x^2+2x+5|+\frac{3\arctan(\frac{x+1}{2})}{2}+C$$

This obviously is the correct answer, however, when I try to solve this with trig-sub (which is the first thing that came to my mind when I looked at the problem, hence my frustration) I am getting a similar, albeit incorrect answer:

$$I_1=\int\frac{u}{u^2+4}du+I_2=\int\frac{3}{u^2+4}du$$ $$u = 2\tan\theta$$

$$du = 2\sec^2\theta d\theta$$

$$I_1=\int\frac{2\tan\theta}{4\tan^2\theta+4}\cdot\frac{2\sec^2\theta}{1}d\theta$$ $$I_1=\int\frac{2\tan\theta}{4\sec^2\theta}\cdot\frac{2\sec^2\theta}{1}d\theta$$ $$I_1=\int\frac{2\tan\theta}{2}d\theta$$ $$I_1=\int \tan\theta$$ $$I_2=3\int\frac{2\sec^2\theta}{4\sec^2\theta}d\theta$$ $$I_2=3\int\frac{1}{2}d\theta$$ $$I_2=\frac{3\theta}{2}$$ $$\int \tan\theta d\theta+\frac{3\theta}{2}$$ $$-\ln|\cos\theta|+\frac{3\theta}{2}$$ Now I put it back into terms of x like I did when solving it using u-sub: $$-\ln\left|\frac{2}{u^2+4}\right|+\frac{3}{2}\arctan\frac{x+1}{2}$$ Since $$u=x+1$$: $$-\ln\left|\frac{2}{(x+1)^2+4}\right|+\frac{3}{2}\arctan(\frac{x+1}{2})+C$$

But this is obviously wrong, since it looks like the $$ln$$ should have a $$\frac{1}{2}$$ in front of it, so something must be wrong with my trig-sub on $$I_1$$? I know it's a lot to read but I just wanted to put it step by step to see if there's some dumb algebraic mistake I made. If anyone can help, thanks a ton in advance.

• Still reading. First solution seems good. Feb 22 '19 at 6:20
• Note the final integral of $\tan(x)$ is $\ln(\sec(x))$ and $\sec(x)=(\tan^2(x)+1)^{1/2}$...that square root is what is missing Feb 22 '19 at 6:27
• It's all good until you convert back to x on the last couple lines. You should indeed get that $-\log(\cos(\arctan(\tfrac{x+1}{2}))) = \tfrac{1}{2} \log(x^2+2x+5)$ Feb 22 '19 at 6:27
• $\cos \theta = \frac {2} {\sqrt {u^2+4}}.$ Right? Feb 22 '19 at 6:28

You plugged in the wrong expression for $$\cos \theta$$, it should be $$2/\sqrt{u^2+4}$$. Notice that the Pythagorean theorem tells you that the length of the hypotenuse should be $$\sqrt{x^2+2x+5}$$.
Note the minus sign outside of the logarithm. $$-\ln\left|\dfrac{2}{\sqrt{u^2+4}} \right|=\ln\left|\dfrac{\sqrt{u^2+4}}{2}\right|$$
Since $$\sqrt{f(x)}$$ can be written as $$(f(x))^{1/2}$$. Therefore by the logarithm properties.
1. $$\ln \left|\sqrt{u^2+4}\right|=1/2\cdot\ln\left|u^2+4\right|$$
2. $$1/2\cdot\ln\left|(u^2+4)/\sqrt{2}\right|=1/2\cdot\ln\left|u^2+4\right|-1/2\cdot\ln\sqrt{2}$$ which gets absorbed in the constant $$C$$.