Evaluate $\displaystyle \int \dfrac{x^2}{x^4 + x^2 + 1} \; dx$
$\begin{aligned}
\text{Let } I & = \int \dfrac{x^2}{x^4 + x^2 + 1} \; dx \\\\
& = \dfrac{1}{2} \int \dfrac{2 x^2}{x^4 + x^2 + 1} \; dx \\\\
& = \dfrac{1}{2} \int \dfrac{\left(x^2 + 1\right) + \left(x^2 - 1\right)}{x^4 + x^2 + 1} \; dx \\\\
& = \dfrac{1}{2} \int \dfrac{x^2 + 1}{x^4 + x^2 + 1} \; dx + \dfrac{1}{2} \int \dfrac{x^2 - 1}{x^4 + x^2 + 1} \; dx \\\\
& = \dfrac{1}{2} \int \dfrac{1 + \dfrac{1}{x^2}}{x^2 + 1 + \dfrac{1}{x^2}} \; dx + \dfrac{1}{2} \int \dfrac{1 - \dfrac{1}{x^2}}{x^2 + 1 + \dfrac{1}{x^2}} \; dx \\\\
& = \dfrac{1}{2} I_1 + \dfrac{1}{2} I_2 \;\;\; \cdots (1)
\end{aligned}$
Now, $\left(x - \dfrac{1}{x}\right)^2 = x^2 + \dfrac{1}{x^2} - 2$
$\implies$ $x^2 + \dfrac{1}{x^2} = \left(x - \dfrac{1}{x}\right)^2 + 2$ $\;\;\; \cdots$ (2a)
and $\left(x + \dfrac{1}{x}\right)^2 = x^2 + \dfrac{1}{x^2} + 2$
$\implies$ $x^2 + \dfrac{1}{x^2} = \left(x + \dfrac{1}{x}\right)^2 - 2$ $\;\;\; \cdots$ (2b)
Consider $I_1 = \displaystyle \int \dfrac{\left(1 + \dfrac{1}{x^2}\right) \; dx}{\left(x^2 + \dfrac{1}{x^2}\right) + 1}$ $\;\;\; \cdots$ (3)
In view of equation (2a), equation (3) can be written as
$\begin{aligned}
I_1 & = \displaystyle \int \dfrac{\left(1 + \dfrac{1}{x^2}\right) \; dx}{\left(x - \dfrac{1}{x}\right)^2 + 2 + 1} \\\\
& = \displaystyle \int \dfrac{\left(1 + \dfrac{1}{x^2}\right) \; dx}{\left(x - \dfrac{1}{x}\right)^2 + 3} \;\;\; \cdots (3a)
\end{aligned}$
In equation (3a), let $x - \dfrac{1}{x} = u$ $\;\;\; \cdots$ (4a)
Differentiating equation (4a) gives
$\left(1 + \dfrac{1}{x^2}\right) \; dx = du$ $\;\;\; \cdots$ (4b)
In view of equations (4a) and (4b), equation (3a) becomes,
$\begin{aligned}
I_1 & = \int \dfrac{du}{u^2 + 3} \\\\
& = \int \dfrac{du}{\left(u\right)^2 + \left(\sqrt{3}\right)^2} \\\\
& = \dfrac{1}{\sqrt{3}} \tan^{-1} \left(\dfrac{u}{\sqrt{3}}\right) + c_1 \;\;\; \left[\text{Note: } \int \dfrac{dx}{x^2 + a^2} = \dfrac{1}{a} \tan^{-1} \left(\dfrac{x}{a}\right ) + c\right] \\\\
& = \dfrac{1}{\sqrt{3}} \tan^{-1} \left(\dfrac{x - \dfrac{1}{x}}{\sqrt{3}}\right) + c_1 \;\;\; \left[\text{From equation (4a)}\right] \\\\
& = \dfrac{1}{\sqrt{3}} \tan^{-1} \left(\dfrac{x^2 - 1}{x \sqrt{3}}\right) + c_1 \;\;\; \cdots (3b)
\end{aligned}$
Consider $I_2 = \displaystyle \int \dfrac{\left(1 - \dfrac{1}{x^2}\right) \; dx}{\left(x^2 + \dfrac{1}{x^2}\right) + 1}$ $\;\;\; \cdots$ (5)
In view of equation (2b), equation (5) can be written as
$\begin{aligned}
I_2 & = \int \dfrac{\left(1 - \dfrac{1}{x^2}\right) \; dx}{\left(x + \dfrac{1}{x}\right)^2 - 2 + 1} \\\\
& = \int \dfrac{\left(1 - \dfrac{1}{x^2}\right) \; dx}{\left(x + \dfrac{1}{x}\right)^2 - 1} \;\;\; \cdots (5a)
\end{aligned}$
In equation (5a), let $x + \dfrac{1}{x} = v$ $\;\;\; \cdots$ (6a)
Differentiating equation (6a) gives
$\left(1 - \dfrac{1}{x^2}\right) \; dx = dv$ $\;\;\; \cdots$ (6b)
In view of equations (6a) and (6b), equation (5a) becomes,
$\begin{aligned}
I_2 & = \int \dfrac{dv}{v^2 - 1} \\\\
& = \int \dfrac{dv}{\left(v\right)^2 - \left(1\right)^2} \\\\
& = \dfrac{1}{2} \log \left|\dfrac{v - 1}{v + 1}\right| + c_2 \;\;\; \left[\text{Note: } \int \dfrac{dx}{x^2 - a^2} = \dfrac{1}{2a} \log \left|\dfrac{x - a}{x + a}\right| + c\right] \\\\
& = \dfrac{1}{2} \log \left|\dfrac{x + \dfrac{1}{x} - 1}{x + \dfrac{1}{x} + 1}\right| + c_2 \;\;\; \left[\text{From equation (6a)}\right] \\\\
& = \dfrac{1}{2} \log \left|\dfrac{x^2 - x + 1}{x^2 + x + 1}\right| + c_2 \;\;\; \cdots (5b)
\end{aligned}$
Putting equations (3b) and (5b) in equation (1) gives
$I = \dfrac{1}{2 \sqrt{3}} \tan^{-1} \left(\dfrac{x^2 - 1}{x \sqrt{3}}\right) + \dfrac{1}{4} \log \left|\dfrac{x^2 - x +1}{x^2 + x + 1}\right| + c$
where $c = \dfrac{c_1}{2} + \dfrac{c_2}{2}$