How to solve this Ordinary Differential Equation (ODE)? By using the method of undetermined coeficiens, find the particular solution $y_p$ for this inhomogenous differential equation.
$$y''+y= \sin x + x\cos x$$
I have find the roots which are $\pm i$.
and the complementary function $y_c= (C_1 \cos x + C_2\sin x)$
The answer given is : $(x/4)[x\sin x-\cos x]$
 A: By setting $C_1=C_1(x)$ and $C_2=C_2(x)$, you have $y=C_1(x)\cos x+C_2(x)\sin x$. Substitute this into the equation. You will have a system of equations on the derivatives of $C_1,C_2$. You should assume that the sum of all terms containing $C_1''(x)$ and $C_2''(x)$ is zero. Now find $C_1(x)$ and $C_2(x)$. I.e:
$$\begin{array}{l}
y=C_1(x)\cos x+C_2(x)\sin x\\
y'=-C_1(x)\sin x+C_2(x)\cos x+C_1'(x)\cos x+C_2'(x)\sin x\\
\begin{align*}y''=&-C_1(x)\cos x-C_2(x)\sin x-C_1'(x)\sin x+C_2'(x)\cos x\\&-C_1'(x)\sin x+C_2'(x)\cos x+C_1''(x)\cos x+C_2''(x)\sin  x\end{align*}\\
\end{array}$$
$$\begin{align*}
\sin x+x\cos x &=y''+y=C_1(x)\cos x+C_2(x)\sin x-C_1(x)\cos x-C_2(x)\sin x\\&-C_1'(x)\sin x+C_2'(x)\cos x-C_1'(x)\sin x+C_2'(x)\cos x+C_1''(x)\cos x+C_2''(x)\sin  x
\end{align*}$$
$$\left\{\begin{array}{l}
2C_2'(x)\cos x-2C_1'(x)\sin x=\sin x+x\cos x\\
C_1''(x)\cos x+C_2''(x)\sin  x=0
\end{array}\right.$$
$$C_2'(x)=\frac12\left(\tan x+x+C_1'(x)\tan x\right)$$
$$C_2''(x)=\frac12\left(\frac{1}{1+x^2}+1+C_1'(x)\frac{1}{1+x^2}+C_1''(x)\tan x\right)$$
$$0=C_1''(x)\cos x+\frac12\left(\frac{\sin x}{1+x^2}+\sin x+C_1'(x)\frac{\sin x}{1+x^2}+C_1''(x)\cos x\right)$$
$$C_1''(x)+C_1'(x)\frac13\frac{\tan x}{1+x^2}+\frac13\frac{\tan x}{1+x^2}+\frac13\tan x=0$$
Now find $C_1(x)$ and $C_2(x)$.
A: Beside to Dennis's approach, you can use the annihilator's method as well http://www.utdallas.edu/dept/abp/PDF_Files/DE_Folder/Annihilator_Method.pdf. According to this way you will have: $$(D^2+1)^3y=0$$ so we can guess $$y(x)=y_p(x)+y_c(x)\\=A\cos(x)+B\sin(x)+Ex\cos(x)+Fx\sin(x)+Gx^2\cos(x)+Hx^2\sin(x)$$ Now pick up the $y_c(c)$ from the solution . You will have $y_P(x)$.
A: Consider the differential equation
$$
\left(\frac{\mathrm{d}}{\mathrm{d}x}+a\right)y=f(x)\tag{1}
$$
This can be solved using an integrating factor. Suppose
$$
g'(x)=ag(x)\tag{2}
$$
then
$$
\frac{\mathrm{d}}{\mathrm{d}x}(g(x)y)=g(x)y'+ag(x)y=g(x)f(x)\tag{3}
$$
Equation $(3)$ is simply $(1)$ multiplied by $g(x)$. Note that $(2)$ is the same as
$$
\frac{\mathrm{d}}{\mathrm{d}x}\log(g(x))=a\tag{4}
$$
which is satisfied by
$$
g(x)=e^{ax}\tag{5}
$$
plugging $(5)$ back into $(3)$ yields
$$
\frac{\mathrm{d}}{\mathrm{d}x}\left(e^{ax}y\right)=e^{ax}f(x)\tag{6}
$$
which becomes
$$
y=e^{-ax}\int e^{ax}f(x)\,\mathrm{d}x\tag{7}
$$

$y''+y=\sin(x)+x\cos(x)$ is simply
$$
\left(\frac{\mathrm{d}}{\mathrm{d}x}+i\right)\left(\frac{\mathrm{d}}{\mathrm{d}x}-i\right)y=\sin(x)+x\cos(x)\tag{8}
$$
Using $(7)$ once with $a=i$ gives
$$
\begin{align}
\left(\frac{\mathrm{d}}{\mathrm{d}x}-i\right)y
&=e^{-ix}\int e^{ix}(\sin(x)+x\cos(x))\,\mathrm{d}x\\
&=e^{-ix}\left(\frac{x^2}4+\frac{ix}2+c_1\right)-e^{ix}\left(\frac{ix}4+\frac18\right)\tag{9}
\end{align}
$$
Using $(7)$ again with $a=-i$ gives
$$
\begin{align}
y
&=e^{ix}\int e^{-ix}\left(e^{-ix}\left(\frac{x^2}4+\frac{ix}2+c_1\right)-e^{ix}\left(\frac{ix}4+\frac18\right)\right)\,\mathrm{d}x\\
&=e^{-ix}\left(\frac{ix^2}8-\frac x8\right)-e^{ix}\left(\frac{ix^2}8+\frac x8\right)+c_1^\prime e^{-ix}+c_2^\prime e^{ix}\\
&=\frac{x^2}4\sin(x)-\frac x4\cos(x)+c_1^{\prime\prime}\cos(x)+c_2^{\prime\prime}\sin(x)\tag{10}
\end{align}
$$
