Evaluate:
$$
\int xe^x\sin^2x dx
$$
Call the integral $I_1$. I've started by putting
$$
u_1 = \sin^2x\\
du_1 = 2\sin x\cos x\ dx = \sin(2x)dx\\
dv_1 = xe^xdx\\
v_1 = e^x(x-1)
$$
Then:
$$
\begin{align}
I_1 &= u_1v_1 – \int v_1du_1\\
&= e^x(x-1)\sin^2x – \int e^x(x-1)\sin(2x)dx\\
&= e^x(x-1)\sin^2x – \underbrace{\int xe^x\sin(2x)dx}_{I_2} + \underbrace{\int e^x\sin(2x)dx}_{I_3}
\end{align}
$$
$I_3$ seems simpler so I started with that:
$$
I_3 = \int e^x\sin(2x)dx \\
u_3 = \sin(2x)\\
du_3 = 2\cos(2x)\ dx\\
dv_3 = e^x\ dx\\
v_3 = e^x
$$
So it becomes:
$$
I_3 = e^x\sin(2x) – 2\int^x\cos(2x)dx
$$
Skipping a similar step I eventually got:
$$
I_3 = {1\over 5}e^x\left(\sin(2x) – 2\cos(2x)\right)
$$
Placing it back to $I_1$:
$$
I_1 = e^x(x-1)\sin^2x + {1\over 5}e^x\left(\sin(2x) – 2\cos(2x)\right) – \underbrace{\int xe^x\sin(2x)dx}_{I_2}
$$
Consider $I_2$:
$$
u_2 = \sin(2x)\\
du_2 = 2\cos(2x)dx\\
dv_2 = xe^xdx\\
v_2 = e^x(x-1)
$$
Thus:
$$
\begin{align}
I_2 &= u_2v_2 – \int v_2du_2 \\
&= e^x(x-1)\sin(2x) – 2\int e^x(x-1)\cos(2x)dx\\
&= e^x(x-1)\sin(2x) – 2\left(\underbrace{\int xe^x\cos(2x)dx}_{I_3} – \underbrace{\int e^x\cos(2x)dx}_{I_4}\right)
\end{align}
$$
$I_4$ is very similar to $I_3$, here is the result:
$$
I_4 = {1\over 5}e^x(\cos(2x) + 2\sin(2x))
$$
Summarizing so far:
$$
I_1 = e^x(x-1)\sin^2x + {1\over 5}e^x\left(\sin(2x) – 2\cos(2x)\right) – e^x(x-1)\sin(2x) -\\
-2\left(\underbrace{\int xe^x\cos(2x)dx}_{I_3} – {1\over 5}e^x(\cos(2x) + 2\sin(2x))\right)
$$
At this point I'm left with $I_3$ only. I've stopped here because it seem like the initial split (or the one that follows) makes things too complicated.
Is there a simpler way to solve the integral? Perhaps some smart substitution/split-into-parts might work. Even though the problem is given to master integration by parts technique, it seems like my approach is overcomplicating the whole solution.
Best Answer
Hint: \begin{align*} I &\;=\; \int dx \, x\, e^x\, \sin^2 x\\ &\;=\; \int dx \, x\, e^x\, \frac{1}{2}\left[1 - \cos(2 x)\right]\\ &\;=\; \frac{1}{2}\left[ \int dx \, x\, e^x \;-\; \mathrm{Re}\int dx \, x\, e^{(1+2 i)x}\right] \end{align*} Can you take it from there?
Edited to add:
Hint 2:
\begin{align*} I_2 &\;=\; \mathrm{Re}\int dx \, x\, e^{(1+2 i)x}\\ &\;=\; \mathrm{Re}\, {\Biggl.\frac{d}{dc}\int dx \, e^{c\, x}\;\Biggr|}_{c = 1+2i} \end{align*}