Integrate $\int x e^{x} \sin x dx$

Solution without complex numbers:

Let $I=\int e^x x\sin xdx$ Integrating by parts:

$$I=e^x x\sin x-\int e^x x\cos xdx-\int e^x\sin xdx$$

Then one more time by parts:

$$\int e^x x\cos xdx=e^x x\cos x + I-\int e^x\cos xdx$$

So:

$$2I=e^x x\sin x-e^x x\cos x+\int e^x(\cos x-\sin x)dx$$

Now (by parts again or by direct observation):

$$\int e^x(\cos x-\sin x)dx=e^x \cos x$$

So:

$$I=\frac{e^x x\sin x-e^x x\cos x+e^x \cos x}{2}$$


If one may recall that $\sin(x)=\Im e^{ix}$, then

$$\int x\sin(x)e^x\ dx=\Im\int xe^{(1+i)x}\ dx$$

With a quick integration by parts, we have

$$=\Im\left(\frac1{1+i}xe^{(1+i)x}-\frac1{1+i}\int e^{(1+i)x}\ dx\right)\\=\Im\left(\frac1{1+i}xe^{(1+i)x}-\frac1{(1+i)^2}e^{(1+i)x}+C\right)\\=\frac12\left(x\sin(x)e^x-x\cos(x)e^x+\cos(x)e^x\right)$$


HINTS:

Use Euler's Formula to write $$x\sin(x)e^x=\text{Im}(xe^{(1+i)x})$$Integrate $\int xe^{(1+i)x}\,dx$ by parts with $u=x$ and $v=\frac{e^{(1+i)x}}{1+i}$ and finish by taking the imaginary part.