As suggested in the title, I am given the following integral:
$$\int\frac{2x^3+x^2+1}{x^2+x-2}\space dx$$
I have tried to solve it several times, but I wind up with the wrong answer, although its close. I assume there is a blunder somewhere.
Applying long division, we have that
$$\frac{2x^3+x^2+1}{x^2+x-2} = 2x - 1 + \frac{-3x-1}{x^2+x-2}$$
I note now that I may write this as
$$\frac{2x^3+x^2+1}{x^2+x-2} = 2x - 1 + \frac{(-1)3x+1}{x^2+x-2} = 2x - 1 - \frac{3x+1}{x^2+x-2}$$
I did not notice this while doing the task originally, but I am having a hard time seeing how this will make answer different. (After calculating it on paper: it didn't.)
Thus, we have the integral
$$\int 2x - 1 \space dx - \int \frac{3x+1}{x^2+x-2}\space dx$$
The first integral is trivial. For the second one, we have that
$$\frac{3x+1}{(x-1)(x+2)} = \frac{A}{x-1} + \frac{B}{x+2} = \frac{A(x+2)+B(x-1)}{(x-1)(x+2)}$$
We have the set $A + B = 3, \space 2A - B = 1$.This gives us the solutions $A = \frac{4}{3}$ and $B = \frac{5}{3}$
Thus, we are left with
$x^2 - x - \int \frac{3x+1}{x^2+x-2}\space dx = x^2 - x - \int \frac{4/3}{x-1} + \frac{5/3}{x+2} \space dx = x^2 - x - \frac{4}{3}\ln{|x-1|}-\frac{5}{3}\ln{|x+2|} + C$
I'm having a hard time finding my mistake here.
EDIT: Seems like I made my mistake in the long division part, confirming now.
You're off at the start, with your long division: in particular, the numerator of the remainder needs to be $5x - 1$.
$$\frac{2x^3+x^2+0\cdot x +1}{x^2+x-2} = 2x - 1 + \frac{5x - 1}{x^2+x-2} = 2x - 1 + \frac{5x-1}{(x+2)(x-1)}$$ Procedurally, your approach is just fine: once you correct for this mistake, you should obtain the correct result.
Note also that in the logarithm components of your answer, we can "consolidate":
$$a\ln |f(x)| + b\ln |g(x)| = \ln|(f(x))^a| + \ln|(g(x))^b| = \ln|(f(x))^a\cdot (g(x))^b|$$
and$$a\ln |f(x)| - b\ln |g(x)| = \ln|(f(x))^a| - \ln|(g(x))^b| = \ln\left|\dfrac{(f(x))^a}{(g(x))^b}\right|$$