stuck with (last) partial integration step for $\int x^2 e^{2x} \, dx$ I am stuck with this integral in the last step of partial integration:
\begin{align}
\int x^2 e^{2x}\,dx & = \frac{1}{2}e^{2x}x^2-\int \frac{1}{2}e^{2x} 2x \,dx \\[6pt]
& = \frac{1}{2}e^{2x}x^2-\int e^{2x} x \, dx \\[6pt]
& = \frac{1}{2}e^{2x}x^2-\frac{1}{2}e^{2x}x-\int \frac{1}{2}e^{2x} \,dx\\[6pt]
& = \frac{1}{2}e^{2x}x^2-\frac{1}{2}e^{2x}x- \frac{1}{2} \int e^{2x} \,dx
\end{align}
I have problems with evalautating the final integral, especially with the factoring of constants (the $\frac{1}{2}$ for the integral. The solution for the last integral is 
$+\frac{1}{4}e^{2x}$, but it seems I have a knot in my brain and can't get the last step right, because I would solve it to $-\frac{1}{4}e^{2x}$...
How does the last step evaluate to positive?
 A: Using integration by parts on $\int x^2 e^{2x} dx$, we let $u=x^2$ and $dv=e^{2x}dx$.  So, that $du=2xdx$ and $v=\frac12 e^{2x}$. Thus, 
$$\int x^2 e^{2x} dx = \frac12 x^2e^{2x}- \int xe^{2x}dx$$
For the integral $\int xe^{2x}dx$, we integrate by parts again.  To that end, let $u=x$ and $dv=e^{2x}dx$ so that $du=dx$ and $v=\frac12 e^{2x}$.   Then, 
$$\int xe^{2x}dx=\frac12 x e^{2x}-\frac12 \int e^{2x}dx$$
using $\int e^{2x}dx = \frac12 e^{2x}+C$ where $C$ is an integration constant, we have 
$$\begin{align} 
\int x^2 e^{2x} dx & =\frac12 x^2e^{2x}- \int xe^{2x}dx\\
& =\frac12 x^2e^{2x}-\left(\frac12 xe^{2x}-\frac14 e^{2x}\right)+C \\
& =\frac12 x^2e^{2x}-\frac12 xe^{2x}+\frac14 e^{2x}+C 
\end{align}$$
A: If it's easier for you, you could find the same result via differentiation under the integral sign.  Here's how:
First notice that $\partial_\beta e^{\beta x} = xe^{\beta x}$ and $\partial_\beta \partial_\beta e^{\beta x} = x^2e^{\beta x}$.  Then we have:
$$\begin{align}\int x^2 e^{\beta x}\,dx &= \int \partial_\beta \partial_\beta e^{\beta x}\,dx \\ &= \partial_\beta \partial_\beta \int e^{\beta x}\,dx \\ &= \partial_\beta \partial_\beta \frac {e^{\beta x}}{\beta} + C \\ &= \partial_\beta \frac{\beta xe^{\beta x}-e^{\beta x}}{\beta^2} + C \\ &= \frac{(xe^{\beta x}+\beta x^2 e^{\beta x}-x e^{\beta x})\beta^2-2\beta(\beta xe^{\beta x} -e^{\beta x})}{\beta^4} + C\end{align}$$
Now, let $\beta = 2$ and simplify.
Notice: I know that last expression looks pretty complex, but it was obtained with just the quotient rule, product rule, and chain rule -- so it's pretty straightforward.  In fact, this highlights what differentiation under the integral sign does for you -- it turns an integral that would normally take several steps (sometimes several very difficult steps) into an easy integral and then a differentiation that takes several steps.  But derivatives are usually easier than integrals so that's not such a bad thing.
A: you can evaluate $$\int x^2 e^{2x}\, dx $$ by identfying $$y= e^{-2x}\int x^2 e^{2x}\, dx$$ as a particular solution of the differential equation $$y' + 2y = x^2. \tag 1$$  and look for a solution of the form $$y = ax^2 + bx + c, \quad y'= 2ax + b  $$ subbing in $(1)$ and equation the coefficients we get $$2ax + b + 2(ax^2 + b x + c) = x^2\to a = \frac 12, b = -\frac 12, c = \frac 14.$$ therefore 
$$\int x^2 e^{2x}\, dx  = \left(\frac 12 x^2 - \frac 12 x + \frac 14\right)e^{2x} + C$$
