# Evaluating $\int\frac{x^2+1}{(x^2-2x+2)^2}dx$ - Section 7.3, #28 in Stewart Calculus 8th Ed.

I'd like to evaluate $$I=\int\frac{x^2+1}{(x^2-2x+2)^2}dx.$$

According to WolframAlpha, the answer is $$\frac{1}{2}\bigg(\frac{x-3}{x^2-2x+2}-3\tan^{-1}(1-x)\bigg)+C.$$

To ensure that my answer is correct, I'd like to match it with this answer.

First I complete the square by writing the denominator as $((x-1)^2+1)^2$, then use a trig-sub $x-1=\tan\theta$ so $dx=\sec^2\theta d\theta.$

Then $$I=\int\frac{(\tan\theta +1)^2+1}{\sec^4\theta}\sec^2\theta d\theta\\=\int\frac{\tan^2\theta+2\tan\theta+2}{\sec^2\theta}d\theta\\=\int\sin^2\theta +2\sin\theta\cos\theta+2\cos^2\theta d\theta\\=\int\bigg(\frac{1}{2}-\frac{\cos(2\theta)}{2}\bigg)+\sin(2\theta)+(1+\cos(2\theta))d\theta\\=\int\frac{3}{2}+\frac{\cos(2\theta)}{2}+\sin(2\theta)d\theta\\=\frac{3\theta}{2}+\frac{\sin(2\theta)}{4}-\frac{\cos(2\theta)}{2}+C\\=\frac{3\theta}{2}+\frac{\sin\theta \cos\theta}{2}-\frac{1-2\sin^2\theta}{2}+C.$$

Here's a picture corresponding to my trig-sub.

From the picture, I conclude $$I=\frac{3\tan^{-1}(x-1)}{2}+\frac{1}{2}\frac{x-1}{\sqrt{x^2-2x+2}}\frac{1}{\sqrt{x^2-2x+2}}- \frac{1-2\frac{(x-1)^2}{x^2-2x+2}}{2}+C\\=\frac{-3\tan^{-1}(1-x)}{2}+\frac{x-1}{2(x^2-2x+2)}-\frac{1}{2}+\frac{(x-1)^2}{x^2-2x+2}+C.$$

Although the $\arctan$ portion of the answer matches Wolfram, the remaining portion does not (since there is a square in the numerator after finding a common denominator). Where am I making the mistake?

I've also tried using the identity $\cos(2\theta)= 2\cos^2\theta-1$ instead of $\cos(2\theta)= 1-2\sin^2\theta$, but the same issue occurs.

Your work is correct; the only difference between your antiderivative and the one calculated by WolframAlpha is a constant of integration, $1/2$. You may verify that $$\frac{(x-1)^2}{x^2-2 x+2}+\frac{x-1}{2 \left(x^2-2 x+2\right)}-\frac{1}{2} = \frac{x^2-x-1}{2 \left(x^2-2 x+2\right)},$$ and it follows that $$\frac{x^2-x-1}{2 \left(x^2-2 x+2\right)}-\frac{x-3}{2 \left(x^2-2 x+2\right)} = \frac{1}{2}.$$