Indefinite Integration

Evaluate $\displaystyle \int \dfrac{x^2 \; e^x}{\left(x + 2\right)^2} \; dx$


$\begin{aligned} \text{Let } I & = \int \dfrac{x^2 \; e^x}{\left(x + 2\right)^2} \; dx \\\\ & = \int e^x \left\{\dfrac{x^2 + 4 x + 4 - 4 x - 4}{\left(x + 2\right)^2}\right\} \; dx \\\\ & = \int e^x \left\{\dfrac{\left(x + 2\right)^2 - 4 \left(x + 1\right)}{\left(x + 2\right)^2}\right\} \; dx \\\\ & = \int e^x \; dx - 4 \int e^x \left\{\dfrac{x + 1}{\left(x + 2\right)^2}\right\} \; dx \\\\ & = e^x - 4 \int e^x \left\{\dfrac{x + 2 - 1}{\left(x + 2\right)^2}\right\} \; dx \\\\ & = e^x - 4 \int e^x \left\{\dfrac{x + 2}{\left(x + 2\right)^2} - \dfrac{1}{\left(x + 2\right)^2}\right\} \; dx \\\\ & = e^x - 4 \int e^x \left\{\dfrac{1}{x + 2} - \dfrac{1}{\left(x + 2\right)^2}\right\} \; dx \\\\ & \left[\text{Note: } \int e^x \left[f \left(x\right) + f'\left(x\right) \; dx\right] = e^x f\left(x\right) + c\right] \\\\ & \text{Here, if } f\left(x\right) = \dfrac{1}{x + 2}, \text{ then } f'\left(x\right) = \dfrac{-1}{\left(x + 2\right)^2} \\\\ \therefore \; I & = e^x - \dfrac{4 \; e^x}{x + 2} + c \\\\ & = e^x \left(\dfrac{x + 2 - 4}{x + 2}\right) + c \\\\ & = e^x \left(\dfrac{x - 2}{x + 2}\right) + c \end{aligned}$