<s>[INST] Evaluate $\int \frac{x^2 + x + 1}{(x+1)^2(x+2)}dx$ via partial fractions $\int \frac{x^2 + x + 1}{(x+1)^2(x+2)}dx$
= $ \int \frac{Ax+B}{(x+1)} + \frac{Cx+B}{(x+1)^2} + \frac{Dx+E}{x+2}$
= $\int (Ax+B)(x+1)(x+2) + (Cx+B)(x+2) + (Dx+E)(x+1)^2$
= $ \int Ax^3 + 3Ax^2 + 2Ax + Bx^2 + 3Bx + 2B + Cx^2 + 2Cx + Bx + 2B + Dx^3 + 2Dx^2 + Dx + Ex^3 + 2Ex^2 + E$
= $ \int (A + D + E)x^3 + (3A + B + C + 2D + 2E)x^2 + (2A + 2C + 4B + D)x + (4B + E)$
Turn into matrix, find reduced row echelon form to solve system of equations:  
$\begin{bmatrix}
0 & 0 & 0 & 0 & 0 & 0 \\
1 & 0 & 0 & 1 & 1 & 0 \\
3 & 1 & 1 & 2 & 2 & 1 \\
2 & 4 & 2 & 1 & 0 & 1 \\
0 & 4 & 0 & 0 & 1 & 1 \\
\end{bmatrix}$
This is where things go wrong, apparently this doesn't reduce down properly :( and I have been relying on RREF to solve systems of equations everytime up until now.
I am also confused where the $x^2 + x + 1$ is supposed to go exactly. I know I put it into the system of equations later but until then, I feel like I kinda just ignored it and left it out of all my work up until then (is that okay?).
Other note: I recognize that this is a proper rational fraction so no long division is nesecary and that this has irreducible factors that are repeated so that is why I split them up into the partial fractions up above in that manner. Did I miss any intermittent steps that made the RREF turn out wrong? I am not sure where I went wrong thus far either
 [/INST] Another way without having to solve equations:
The function
$$f(x) = \frac{x^2 + x+1}{(x+1)^2 (x+2)}$$
has a simple pole at $x = -2$ and a second order pole at $x = -1$. Let's denote the the singular parts of the expansions around $x = -2$  and $x = -1$ by $P_1(x)$ and $P_2(x)$, respectively. The partial fraction expansion can then be written as:
$$f(x) = P_1(x) + P_2(x)$$
This follows from the fact that $g(x) = f(x) - \left[P_1(x) + P_2(x)\right]$ does not have any singularities, as all the singularities in $f(x)$ have been subtracted by subtracting the ones contained in the singular parts of the Laurent expansions around each pole. This means that $g(x)$ is a rational function without any singularities, therefore $g(x)$ is a polynomial (after removing the removable singularities). However, we can also see that $g(x)$ tends to zero at infinity, therefore $g(x)$ must be identical to zero.
We can easily find $P_1(x)$ by substituting $x=-2$ in the factor multiplying $\frac{1}{x+2}$ in $f(x)$. This yields:
$$P_1(x) = \frac{3}{x+2}$$
We can find $P_2(x)$ without doing all the work needed to expand around $x=-1$ by observing that for large $x$ we have:
$$f(x)=\frac{1}{x} + \mathcal{O}\left(x^{-2}\right)$$
Therefore we must have:
$$P_2(x) = -\frac{2}{(x+1)} +\mathcal{O}(x+1)^{-2}$$
The leading term of the expansion around $x = -1$ of $f(x)$ is easy to find by substituting $x =-1 $ in the term multiplying $\frac{1}{(x+1)^2}$, this is given by $\frac{1}{(x+1)^2}$, we therefore have:
$$P_2(x) =\frac{1}{(x+1)^2} -\frac{2}{(x+1)}$$
It thus follows that:
$$f(x) = \frac{1}{(x+1)^2} -\frac{2}{(x+1)} +  \frac{3}{x+2}$$
</s>