Evaluate the following integral:
$\int \frac{3+4 x-x^{2}}{(x+2)(x-1)} d x$
First we simplify numerator, we get
$\frac{3+4 x-x^{2}}{(x+2)(x-1)}$
$=\frac{-\left(x^{2}-4 x-3\right)}{x^{2}+x-2}$
$=\frac{-\left(x^{2}+x-5 x-2-1\right)}{x^{2}+x-2}$
$=\frac{-\left(x^{2}+x-2\right)}{x^{2}+x-2}+\frac{5 x+1}{x^{2}+x-2}$
$=-1+\frac{5 x+1}{(x+2)(x-1)}$
Now the denominator is factorized, so let separate the fraction through partial fraction, hence let
$\frac{5 x+1}{(x+2)(x-1)}=\frac{A}{x+2}+\frac{B}{x-1} \ldots \ldots$ (i)
$\Rightarrow \frac{5 x+1}{(x+2)(x-1)}=\frac{A(x-1)+B(x+2)}{(x+2)(x-1)}$
$\Rightarrow 5 x+1=A(x-1)+B(x+2) \ldots \ldots$ (ii)
We need to solve for $A$ and $B$. One way to do this is to pick values for $x$ which will cancel each variable.
Put $x=1$ in the above equation, we get
$\Rightarrow 5(1)+1=A(1-1)+B(1+2)$
$\Rightarrow 6=0+3 B$
$\Rightarrow B=2$
Now put $x=-2$ in equation (ii), we get
$\Rightarrow 5(-2)+1=A((-2)-1)+B((-2)+2)$
$\Rightarrow-9=-3 A+0$
$\Rightarrow A=3$
We put the values of $A$ and $B$ values back into our partial fractions in equation (i) and replace this as the integrand. We get
$\int\left[-1+\frac{5 x+1}{(x+2)(x-1)}\right] d x$
$\Rightarrow \int\left[-1+\frac{\mathrm{A}}{\mathrm{x}+2}+\frac{\mathrm{B}}{\mathrm{x}-1}\right] \mathrm{dx}$
$\Rightarrow \int\left[-1+\frac{3}{\mathrm{x}+2}+\frac{2}{\mathrm{x}-1}\right] \mathrm{dx}$
Split up the integral,
$\Rightarrow-\int 1 \mathrm{dx}+3 \int\left[\frac{1}{\mathrm{x}+2}\right] \mathrm{dx}+2 \int\left[\frac{1}{\mathrm{x}-1}\right] \mathrm{dx}$
Let substitute $u=x+2 \Rightarrow d u=d x$ and $z=x-1 \Rightarrow d z=d x$, so the above equation becomes,
$\Rightarrow-\int 1 \mathrm{dx}+3 \int\left[\frac{1}{\mathrm{u}}\right] \mathrm{du}+2 \int\left[\frac{1}{\mathrm{z}}\right] \mathrm{dz}$
On integrating we get
$\Rightarrow-x+3 \log |u|+2 \log |z|+C$
Substituting back, we get
$\Rightarrow-x+3 \log |x+2|+2 \log |x-1|+C$
Note: the absolute value signs account for the domain of the natural log function $(x>0)$.
Hence,
$\int \frac{3+4 x-x^{2}}{(x+2)(x-1)} d x=-x+3 \log |x+2|+2 \log |x-1|+C$