Solve $\frac{d^2y}{dx^2}+2\frac{dy}{dx}+y=x \sin^2x$ Solve the differential equation Solve $$\frac{d^2y}{dx^2}+2\frac{dy}{dx}+y=x \sin^2x$$
i used the substitution $\frac{dy}{dx}+y=t$ we get
$$\frac{dt}{dx}+t=x\sin^2x$$ which is linear first order, using integrating factor method we get the solution 
$$te^x=\int xe^x\sin^2xdx+C$$ 
$$te^x=\frac{1}{2} \left(\int xe^xdx-\int xe^x\cos 2xdx\right)+C=\frac{1}{2}\left(P-Q\right)+C \tag{1}$$
we have $$P=\int xe^x=(x-1)e^x+C'$$
now using integration by parts we have
$$Q=\int xe^x \cos2xdx=x\int e^x\cos 2xdx-\int \left(\int e^x\cos 2xdx\right)dx$$
$$\int xe^x \cos2xdx=\frac{xe^x}{5}\left(\cos 2x+2\sin 2x\right)-\frac{1}{5}\int e^x(\cos 2x+2\sin 2x)dx $$
$$\int xe^x \cos2xdx=\frac{xe^x}{5}\left(\cos 2x+2\sin 2x\right)-\frac{1}{5}\left(\frac{e^x}{5}(\cos 2x+2\sin 2x)\right)-\left(\frac{2e^x}{5}(\sin 2x-2 \cos 2x)\right)$$
finally we need to solve another linear differential equation viz:
$$e^x\left(\frac{dy}{dx}+y\right)=\frac{1}{2}\left(P-Q\right)+C$$
which is very tedious.
is  there a good approach?
 A: Hint
If you are as lazy as I am, considering $$\frac{d^2y}{dx^2}+2\frac{dy}{dx}+y=\frac{x}{2}(1-\cos(2x))$$ assume
$$y_p=a+b x+c\sin(2x)+d\cos(2x)+e x\sin(2x)+f x\cos(2x)$$ Replace and identify $a,b,c,d,e,f$. This should be simple.
A: Write the differential equation as  $$(D^2+2D+1)y=x\sin^2(x)=\frac{x}{2}(1-\cos(2x))$$ then a complete solution can be written as $$y=y_r+y_p$$ where $y_r$ is the most general solution of the reduced equation $(D^2+2D+1)y=(D+1)^2y=0$ i.e. $y_r=ae^{-x}+bxe^{-x}$ , where $a,b$ are two arbitrary constants.
And $y_p$ is a one particular integral given by $$y_p=\frac{1}{(D^2+2D+1)}\frac{x}{2}(1-\cos(2x))$$ i.e. $2y_p=(D+1)^{-2}(x)-(D+1)^{-2}(x\cos(2x))$. Now $$(1+D)^{-2}(x)=\{1+\frac{(-2)}{1!}D+\frac{(-2)(-2-1)}{2!}+....\}=(1-2D)x=x-2.$$ Since $D^2x=0,D^3x=0,....$
Next $(1+D)^{-2}(x\cos(2x))=Re((1+D)^{-2}(xe^{\iota 2x}))$. So that $$(1+D)^{-2}(xe^{\iota 2x})=e^{\iota 2x}\frac{1}{1+2(D+2\iota)+(D+2\iota)^2} x.$$ Again expanding as bi-nomial series as in pervious part and then considering real part you can find particular integral $y_p$.
A: The homogeneous part is classical, though the characteristic polynomial has a double root, giving terms $e^{-x}$ and $xe^{-x}$.
The non-homogeneous one is a little harder, though you are lucky that there is no overlap with the roots. Let us try a solution of the form $y=xz+w$. The equation turns to
$$(z''+2z'+z)x+2z'+z+w''+2w'+w=x\frac{1-\cos 2x}2=x\frac{1-\Re(e^{i2x)}}2.$$
The constant term is dealt with by $\dfrac12$, while the other can be handled using complex numbers, giving
$$z=-\frac12\Re\left(\frac{e^{i2x}}{4+2i+1}\right).$$
Next, 
$$w''+2w'+w=\frac12\Re\left(\frac{(i4+1))e^{i2x}}{4+2i+1}\right)$$ and
$$w=\frac12\Re\left(\frac{(i4+1))e^{i2x}}{(4+2i+1)^2}\right).$$
