Evaluate the following integral:
$\int \frac{\mathrm{x}^{2}+\mathrm{x}+1}{\left(\mathrm{x}^{2}+1\right)(\mathrm{x}+2)} \mathrm{dx}$
Denominator is factorised, so let separate the fraction through partial fraction, hence let
$\frac{\mathrm{x}^{2}+\mathrm{x}+1}{\left(\mathrm{x}^{2}+1\right)(\mathrm{x}+2)}=\frac{\mathrm{Ax}+\mathrm{B}}{\mathrm{x}^{2}+1}+\frac{\mathrm{Cx}+\mathrm{D}}{\mathrm{x}+2}$......(i)
$\Rightarrow \frac{\mathrm{x}^{2}+\mathrm{x}+1}{\left(\mathrm{x}^{2}+1\right)(\mathrm{x}+2)}=\frac{(\mathrm{Ax}+\mathrm{B})(\mathrm{x}+2)+(\mathrm{Cx}+\mathrm{D})\left(\mathrm{x}^{2}+1\right)}{\left(\mathrm{x}^{2}+1\right)(\mathrm{x}+2)}$
$\Rightarrow \mathrm{x}^{2}+\mathrm{x}+1=(\mathrm{Ax}+\mathrm{B})(\mathrm{x}+2)+(\mathrm{Cx}+\mathrm{D})\left(\mathrm{x}^{2}+1\right)$
$\Rightarrow \mathrm{x}^{2}+\mathrm{x}+1=\mathrm{Ax}^{2}+2 \mathrm{Ax}+\mathrm{Bx}+2 \mathrm{~B}+\mathrm{Cx}^{3}+\mathrm{Cx}+\mathrm{Dx}^{2}+\mathrm{D}$
$\Rightarrow x^{2}+x+1$ $=C x^{3}+(A+D) x^{2}+(2 A+B+C) x+(2 B+D) \ldots \ldots$ (ii)
We need to solve for $A, B, C$ and $D$. We will equate the like terms we get,
$C=0$.....(iii)
$A+D=1 \Rightarrow A=1-D \ldots \ldots \ldots$ (iv)
$2 \mathrm{~A}+\mathrm{B}+\mathrm{C}=1$
$\Rightarrow 2(1-D)+B+0=1$ (from equation (iii) and (iv))
$\Rightarrow B=2 D-1 \ldots \ldots \ldots(v)$
$2 B+D=1$
$\Rightarrow 2(2 D-1)+D=1$ (from equation (v), we get
$\Rightarrow 4 D-2+D=1$
$\Rightarrow 5 D=3$
$\Rightarrow D=\frac{3}{5} \ldots \ldots \ldots \ldots \ldots .(v i)$
Equation (vi) in (v) and (iv), we get
$\mathrm{B}=2\left(\frac{3}{5}\right)-1=\frac{1}{5}$
$\mathrm{~A}=1-\frac{3}{5}=\frac{2}{5}$
We put the values of $A, B, C$, and $D$ values back into our partial fractions in equation (i) and replace this as the integrand. We get
$\int\left[\frac{\mathrm{x}^{2}+\mathrm{x}+1}{\left(\mathrm{x}^{2}+1\right)(\mathrm{x}+2)}\right] \mathrm{dx}$
$\Rightarrow \int\left[\frac{\mathrm{Ax}+\mathrm{B}}{\mathrm{x}^{2}+1}+\frac{\mathrm{Cx}+\mathrm{D}}{\mathrm{x}+2}\right] \mathrm{dx}$
$\Rightarrow \int\left[\frac{\left(\frac{2}{5}\right) \mathrm{x}+\frac{1}{5}}{\mathrm{x}^{2}+1}+\frac{(0) \mathrm{x}+\frac{3}{5}}{\mathrm{x}+2}\right] \mathrm{dx}$
Split up the integral,
$\Rightarrow \frac{1}{5} \int \frac{2 x}{x^{2}+1} d x+\frac{1}{5} \int \frac{1}{x^{2}+1} d x+\frac{3}{5} \int\left[\frac{1}{x+2}\right] d x$
Let substitute
$u=x^{2}+1 \Rightarrow d u=2 x d x$
$y=x+2 \Rightarrow d y=d x$, so the above equation becomes,
$\Rightarrow \frac{1}{5} \int \frac{1}{u} d u+\frac{1}{5} \int \frac{1}{x^{2}+1} d x+\frac{3}{5} \int\left[\frac{1}{y}\right] d y$
On integrating we get
$\Rightarrow \frac{1}{5} \log |\mathrm{u}|+\frac{1}{5} \tan ^{-1} \mathrm{x}+\frac{3}{5} \log |\mathrm{y}|+\mathrm{C}$
(the standard integral of $\frac{1}{x^{2}+1}=\tan ^{-1} x$ )
Substituting back, we get
$\Rightarrow \frac{1}{5} \log \left|x^{2}+1\right|+\frac{1}{5} \tan ^{-1} x+\frac{3}{5} \log |x+2|+C$
Note: the absolute value signs account for the domain of the natural $\log$ function $(x>0)$.
Hence,
$\int \frac{\mathrm{x}^{2}+\mathrm{x}+1}{\left(\mathrm{x}^{2}+1\right)(\mathrm{x}+2)} \mathrm{dx}=\frac{1}{5} \log \left|\mathrm{x}^{2}+1\right|+\frac{1}{5} \tan ^{-1} \mathrm{x}+\frac{3}{5} \log |\mathrm{x}+2|+\mathrm{C}$