# Evaluate $\int xe^x\sin^2x dx$

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.

• Just a thought, but using the complex form of $\sin(x)$ would make it easier to solve. – Tom Himler Oct 8 '19 at 18:12

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?
\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*}
Let's try the Ansatz$$\int xe^x\cos 2xdx=(A+Bx)e^x\cos 2x+(C+Dx)e^x\sin 2x+K.$$Differentiating and dividing by $$e^x$$,$$x\cos 2x=(A+B+2C+(B+2D)x)\cos 2x+(-2A+C+D+(D-2B)x)\sin 2x.$$We must now simultaneously solve$$A+B+2C=0,\,B+2D=1,\,-2A+C+D=0,\,D-2B=0.$$The solution is$$A=\frac{3}{25},\,B=\frac15,\,C=-\frac{4}{25},\,D=\frac25.$$