Integration by means of partial fraction decomposition I'm trying to solve this indefinite integral by means of partial fraction decomposition:
$\int\dfrac{x+1}{\left(x^2+4x+5\right)^2}\ dx$.
The denominator has complex (but not real) roots because $\Delta<0$; so, according with my calculus book, i try to decompose the integrand function in this form:
$\dfrac{x+1}{\left(x^2+4x+5\right)^2}=
\dfrac{Ax+B}{\left(x^2+4x+5\right)}+\dfrac{Cx+D}{\left(x^2+4x+5\right)^2}$.
I get:
$\dfrac{x+1}{\left(x^2+4x+5\right)^2}=
\dfrac{\left(Ax+B\right)\left(x^2+4x+5\right)+Cx+D}{\left(x^2+4x+5\right)^2}$.
Multiplying the right term:
$\dfrac{x+1}{\left(x^2+4x+5\right)^2}=
\dfrac{Ax^3+4Ax^2+5Ax+Bx^2+4Bx+5B+Cx+D}{\left(x^2+4x+5\right)^2}$.
Now i collect the terms with the same pwer of $x$:
$\dfrac{x+1}{\left(x^2+4x+5\right)^2}=
\dfrac{Ax^3+\left(4A+B\right)x^2+\left(5A+4B+C\right)x+D+ 5B}{\left(x^2+4x+5\right)^2}$.
Now i equate the two numerators:
$x+1=Ax^3+\left(4A+B\right)x^2+\left(5A+4B+C\right)x+D$
and equate term by term: i get:
$A=0$, $B=0$, $C=1$, $D=1$.
With these values i get a correct identity:
$\dfrac{x+1}{\left(x^2+4x+5\right)^2}=
\dfrac{x+1}{\left(x^2+4x+5\right)^2}$
but this is unuseful in order to solve the integral.
Where is my mistake ?
 A: Here is an easy way
$$\int { \frac { x+1 }{ \left( x^{ 2 }+4x+5 \right) ^{ 2 } }  } dx=\frac { 1 }{ 2 } \int { \frac { 2x+4-2 }{ \left( x^{ 2 }+4x+5 \right) ^{ 2 } }  } dx=\\ =\frac { 1 }{ 2 } \int { \frac { 2x+4 }{ \left( x^{ 2 }+4x+5 \right) ^{ 2 } } dx-\int { \frac { dx }{ \left( x^{ 2 }+4x+5 \right) ^{ 2 } }  }  } =\\ =\frac { 1 }{ 2 } \underset { { I }_{ 1 } }{ \underbrace { \int { \frac { d\left( x^{ 2 }+4x+5 \right)  }{ \left( x^{ 2 }+4x+5 \right) ^{ 2 } }  }  }  } -\underset { { I }_{ 2 } }{ \underbrace { \int { \frac { d\left( x+2 \right)  }{ { \left( { \left( x+2 \right)  }^{ 2 }+1 \right)  }^{ 2 } }  }  }  } =$$
Obviously,$$\\ { I }_{ 1 }=-\frac { 1 }{ 2\left( x^{ 2 }+4x+5 \right)  } ,$$
now,let calculate ${ I }_{ 2 }$,substitute here $x+2=\tan { z } $,so that $${ I }_{ 2 }=\int { \frac { d\tan { z }  }{ { \left( { \tan ^{ 2 }{ z }  }+1 \right)  }^{ 2 } }  } =\int { \frac { \cos ^{ 4 }{ z }  }{ \cos ^{ 2 }{ z }  }  } dz=\int { \cos ^{ 2 }{ z } =\frac { 1 }{ 2 } \int { \left( 1+\cos { 2z }  \right
) dz }  } =\frac { 1 }{ 2 } \left( z+\frac { \sin { 2z }  }{ 2 }  \right) $$
finally,

$$\int { \frac { x+1 }{ \left( x^{ 2 }+4x+5 \right) ^{ 2 } }  } dx=\frac { 1 }{ 2 } \left( -\frac { 1 }{ \left( x^{ 2 }+4x+5 \right)  } -\arctan { \left( x+2 \right) -\frac { \sin { 2\left( \arctan { \left( x+2 \right)  }  \right)  }  }{ 2 }  }  \right) +C$$

A: As suggested in the comment directly use Trigonometric substitution
As $x^2+4x+5=(x+2)^2+1^2,$ let $\arctan(x+2)=y\implies x+2=\tan y$
$$2I\int\dfrac{x+1}{(x^2+4x+5)^2}dx=\int(\tan y-1)\cos^2y\ dy$$
$$4I=2\int(\sin2y-1-\cos2y)dy=-\sin2y-2y-\cos2y+K$$
Now $\sin2y=\dfrac{2\tan y}{1+\tan^2y}=\cdots$
and $\cos2y=\dfrac{1-\tan^2y}{1+\tan^2y}=\dfrac2{1+\tan^2y}-1=\cdots$
A: Note that we can write the partial fraction expansion of $\frac{1}{(x+4x+5)^2}$ as
$$\frac{1}{(x+4x+5)^2}=\frac{1}{(x-r)^2(x-r^*)^2}=\frac{A}{x-r}+\frac{B}{(x-r)^2}+\frac{C}{x-r^*}+\frac{D}{(x-r^*)^2}$$
where $r=-2+i$ and $r^*=-2- i$.
Multiplying by $(x-r)^2$ and letting $x\to r$ reveals that $B=\frac{1}{(r-r^*)^2}=-\frac14$.
Multiplying by $(x-r)^2$, taking a derivative with respect to $x$, and letting $x\to r$ reveals that $A=-\frac{2}{(r-r^*)^3}=-\frac{i}{4}$.
Multiplying by $(x-r^*)^2$ and letting $x\to r^*$ reveals that $D=\frac{1}{(r^*-r)^2}=-\frac14$.
Multiplying by $(x-r^*)^2$, taking a derivative with respect to $x$, and letting $x\to r^*$ reveals that $C=\frac{2}{(r-r^*)^3}=\frac{i}{4}$.

