# Eye Of The Tiger

Evaluate

$\int \frac{x^2e^x}{(x+2)^2}\;dx$

is an exercise accompanied my previous post “Integration by Parts Done Right“. It is a special case of

$\int \frac{x^2e^x}{(x+\boxed{a})^2}\;dx$.

For various $a$, Omega CAS Explorer gives

$\int \frac{x^2}{(x+a)^2}e^x\;dx$

$= \int \left(\frac{x}{x+a}\right)^2 e^x\;dx$

$= \int \left(\frac{x+a-a}{x+a}\right)^2 e^x\;dx$

$=\int \frac{(x+a)^2-2a(x+a)+a^2}{(x+a)^2}e^x\;dx$

$= \int \left(1-\frac{2a}{x+a}+\frac{a^2}{(x+a)^2}\right)e^x\;dx$

$= \int e^x-\frac{2a}{x+a}e^x + \frac{a^2}{(x+a)^2}e^x\;dx$

$= \int e^x\;dx-\int \frac{2a}{x+a}e^x\;dx + \int \frac{a^2}{(x+a)^2}e^x\;dx$

$= e^x-2a\int \frac{e^x}{x+a}\;dx + \int \frac{a^2}{(x+a)^2}e^x\;dx$

$= e^x-2a\int \frac{1}{x+a}(e^x)'\;dx + \int \frac{a^2}{(x+a)^2}e^x\;dx$

$= e^x-2a\left(\frac{1}{x+a}e^x-\int (\frac{1}{x+a})' e^x\;dx\right) + \int \frac{a^2}{(x+a)^2}e^x\;dx$

$= e^x-2a\left(\frac{1}{x+a}e^x-\int\frac{-1}{(x+a)^2}e^x\;dx\right)+ \int \frac{a^2}{(x+a)^2}e^x\;dx$

$= e^x-2a\left(\frac{1}{x+a}e^x+\int\frac{1}{(x+a)^2}e^x\;dx\right)+ \int \frac{a^2}{(x+a)^2}e^x\;dx$

$= e^x-\frac{2a}{x+a}e^x-2a\int\frac{e^x}{(x+a)^2}\;dx + a^2\int \frac{e^x}{(x+a)^2}\;dx$

$= e^x-\frac{2a}{x+a}e^x-\left(2a-a^2\right)\int\frac{1}{(x+a)^2}e^x\;dx$

$\overset{2a-a^2=0}{=} \frac{x-a}{x+a}e^x$

$= \begin{cases} e^x, a=0\\ \frac{x-2}{x+2}e^x, a=2\end{cases}$