How to solve $y'+2y=x\sin(x)$ How should I solve $$y'+2y=x\sin(x)$$
I tried this calculation using integrating factor, but it costs me a lot of calculation. Is there better way to solve this kind of problem?
 A: Guess $$y(x)=Ax\sin x +Bx\cos x+C\sin x+D\cos x$$.
Feed that into the left-hand side,.  Equate coefficients, to get four equations in $A,B,C,D$
A: Computing an integrating factor $$\mu(x)=e^{\int2dx}=e^{2x}$$
So we get (after multiplying the equation by $\mu(x$):
$$\frac{d}{dx}(e^{2x}y(x))=e^{2x}x\sin(x)$$
Now integrate with respect to $x$!
A: $y'+2y=x\sin x$ Integrating factor is $e^{\int 2\mathrm dx}=e^{2x}$.
Multiplying by the Integrating factor both side of the equation,
$e^{2x}y'+2e^{2x}y=e^{2x}x\sin x$
$\implies \mathrm d(e^{2x}y)=e^{2x}x\sin x$
$\begin{align}\implies e^{2x}y &=\displaystyle\int e^{2x}x\sin x\mathrm dx=\displaystyle\int e^{2x}x\left(\dfrac{e^{ix}-e^{-ix}}{2i}\right)\mathrm dx\\&=\displaystyle\int \dfrac{e^{2x+ix}x}{2i}\mathrm dx-\displaystyle\int \dfrac{e^{2x-ix}x}{2i}\mathrm dx+C\\&=\dfrac{1}{2i}\left[\dfrac{e^{(2+i)x}x}{2+i}-\dfrac{e^{(2+i)x}}{(2+i)^2}\right]-\dfrac{1}{2i}\left[\dfrac{e^{(2-i)x}x}{2-i}-\dfrac{e^{(2-i)x}}{(2-i)^2}\right]+C\end{align}$
$\implies y=\dfrac{1}{2i}\left[\dfrac{e^{ix}x}{2+i}-\dfrac{e^{ix}}{(2+i)^2}\right]-\dfrac{1}{2i}\left[\dfrac{e^{-ix}x}{2-i}-\dfrac{e^{-ix}}{(2-i)^2}\right]+Ce^{-2x}$
A: Consider the complex equation
$$(ze^{2x})'=xe^{2x}e^{ix}=xe^{(2+i)x}.$$
You integrate by parts,
$$ze^{2x}=x\frac{e^{(2+i)x}}{2+i}-\int \frac{e^{(2+i)x}}{2+i}dx=x\frac{e^{(2+i)x}}{2+i}-\frac{e^{(2+i)x}}{(2+i)^2}+C,$$
then
$$z=x\frac{e^{ix}}{2+i}-\frac{e^{ix}}{3+4i}+Ce^{-2x}.$$
Finally, you take the imaginary part,
$$y=x\frac{2\sin x-\cos x}5-\frac{3\sin x-4\cos x}{25}+Ce^{-2x}.$$
