$\int x\operatorname{e}^x \sin^2 x\ dx$ How to find integral
$$
\int x \operatorname{e}^x \sin^2 x\ dx
$$
Trying to use integration by parts , but stuck on
$$
((\operatorname{e}^x + x\operatorname{e}^x)\sin x + \cos x  \operatorname{e}^x  x)\cos x dx
$$
 A: Integration by parts is actually not necessary if you know Euler's formula.  First, use the reduction formula:
$$\sin^2(x)=\frac{1-\cos(2x)}2$$
Which splits our integral into two parts:
$$2I=\int xe^x\ dx-\int xe^x\cos(2x)\ dx$$
The first is rather simple:
$$\int e^{xt}\ dx=\frac{e^{xt}}t$$
Differentiate both sides and set $t=1$ to get
$$\begin{align}\int xe^x\ dx&=\frac d{dt}\frac{e^{xt}}t\bigg|_{t=1}\\&=(x-1)e^x\end{align}$$
the second may likewise be handled by noting that $\sin(x)=\Im(e^{ix})$:
$$\begin{align}\int e^x\sin(xt)\ dx&=\Im\int e^{(1+it)x}\ dx\\&=\Im\frac{e^{(1+it)x}}{1+it}\\&=\frac{e^x(\sin(xt)-t\cos(xt))}{t^2+1}\end{align}$$
We may then take the derivative and set $t=2$ to get
$$\begin{align}\int xe^x\cos(2x)\ dx&=\frac d{dt}\frac{e^x(\sin(xt)-t\cos(xt))}{t^2+1}\bigg|_{t=2}\\&=\frac{e^x}{25}[(10x-4)\sin(2x)+(5x+3)\cos(2x)]\end{align}$$
We may then add our results to get

$$2\int xe^x\sin^2(x)\ dx=\frac{e^x}{25}[(10x-4)\sin(2x)+(5x+3)\cos(2x)+25(x-1)]$$

Plus a constant.
A: HINT:
Integrate by parts 
$$\int x\cdot e^x\sin^2x\ dx= x\int e^x\sin^2x\ dx-\int\left(\dfrac{dx}{dx}\cdot \int e^x\sin^2x\ dx\right)dx$$
Now use $\cos2x=1-2\sin^2x$ to find $$2I=\int e^x2\sin^2x\ dx=\int e^x\ dx-\int e^x\cos2x\ dx$$
and follow  Integration of $e^{ax}\cos bx$ and $e^{ax}\sin bx$
A: Hint:
Get rid of the annoying square using
$$\sin^2x=\frac{1-\cos 2x}2.$$
Then use complex numbers, noting that 
$$\cos2x=\Re(e^{i2x}).$$
Now, by parts
$$\int xe^x(1-e^{i2x})dx=\int x\left(e^x-e^{(1+i2)x}\right)dx=x\left(e^x-\frac{e^{(1+i2)x}}{1+i2}\right)-\int \left(e^x-e^{(1+i2)x}\right)dx\\
=x\left(e^x-\frac{e^{(1+i2)x}}{1+i2}\right)-\left(e^x-\frac{e^{(1+i2)x}}{(1+i2)^2}\right).$$
The final step will be to expand the complex exponentials, divide by the complex denominators and take the real parts.
$$\frac{e^{ix}}{a+ib}=\frac{(\cos x+i\sin x)(a-ib)}{a^2+b^2}\to\frac{a\cos x+b\sin x}{a^2+b^2}.$$
