TITLE: Integrate $\int x e^{x} \sin x dx$
QUESTION [8 upvotes]: Evaluate:
$$\int x e^{x} \sin x dx$$

Have you ever come across such an integral? I have no idea how to start with the calculation.

REPLY [2 votes]: This can also be solved another way (a little longer but correct nevertheless and could be more basic and readable for people who just started learning calculus):
We will use the results of following(easy - just substitute):
$$
∫ e^x \sin (x) dx = \frac{e^x \sin (x) - e^x \cos (x)}{2} + C
$$
$$
∫ e^{\ln (x)+x}dx = ∫ xe^xdx = xe^x-e^x + C
$$
and
$$
∫ e^x \cos (x) dx = \frac{e^x \sin (x) + e^x \cos (x)}{2} + C
$$
Now, back to the main integral. The main problem is that the formula contains not the usual two but three factors($x$, $e^x$ and $\sin (x)$). However, using basic logarithm and $\exp $ properties we can transform the \exp ression into one with just two factors:
$$
x e^x = e^{\ln (x)} e^x = e^{\ln (x) + x}
$$
this leaves us with
\begin{equation*}
I =
\int xe^xsinx dx =
\int e^{ln(x) + x} \sin (x) dx =
\end{equation*}
integrate by parts with substituting:
$$
\begin{equation*}
\left[
 \begin{alignedat}{2}
 u &= \sin (x) \quad & du &=\cos (x) \\
 dv &= e^{\ln (x)+x} \quad & v &= xe^x-e^x
 \end{alignedat}\,
\right] 
\end{equation*}
$$
$$
= e^xx\sin (x)-e^x\sin (x)-∫ xe^x\cos (x) -e^x\cos (x)dx 
$$
$$
= e^xx\sin (x)-e^x\sin (x)-∫ xe^x\cos (x)dx + ∫ e^x\cos (x)dx
$$
Now, another three factor integral appears, which can also be integrated by parts using the previous trick.
$$
∫ xe^x\cos (x)dx = 
$$
$$
\begin{equation*}
= ∫ e^{\ln (x)+x}\cos (x)dx = 
\left[
 \begin{alignedat}{2}
 u &= \cos (x) \quad & du &=-\sin (x) \\
 dv &= e^{\ln (x)+x} \quad & v &= xe^x-e^x
 \end{alignedat}\,
\right] =
\end{equation*}
$$
$$
= xe^x\cos (x)-e^x\cos (x)+ ∫ x e^x \sin (x) dx - ∫ e^x \sin (x) dx =
$$
$$
= xe^x\cos (x)-e^x\cos (x)+ I - ∫ e^x \sin (x) dx 
$$
Back to the previous equation, plug in the result above flipping the signs accordingly:
$$
I = e^xx\sin (x)-e^x\sin (x) + ∫ e^x\cos (x)dx - xe^x\cos (x)+e^x\cos (x)- I + ∫ e^x \sin (x) dx
$$
Great! We obtained the wanted integral with negative sign. Let's move it to the other side of equation:
$$
2I = e^xx\sin (x)-e^x\sin (x) + ∫ e^x\cos (x)dx - xe^x\cos (x)+e^x\cos (x) + ∫ e^x \sin (x) dx
$$
and plug in the results of simpler integrals:
$$
2I = e^xx\sin (x)-e^x\sin (x) + \frac{e^x \sin (x) + e^x \cos (x)}{2} - xe^x\cos (x)+e^x\cos (x) + \frac{e^x \sin (x) - e^x \cos (x)}{2} + C
$$
now just simplify the right side and divide by 2 to obtain the final result:
$$
I = \frac {xe^x\sin (x) - xe^x\cos (x) +e^x\cos (x)}{2} + C
$$