Particular solution of ordinary differential equation Solve the following initial value problem:
$$y'' + y = \sin x, \quad y = y(x).$$
I can't seem to find the particular solution. I have tried many times but it doesnt seem to work out.
I have tried:
$$ \begin{align}
y(x)&=A\, \cos {x}+B\, \sin{x} \\
y(x)&= A \, x^2  \, \sin{x}\\
y(x)&=A \, x \, e^{ix}
 \end{align}$$
but nothing seems to work out.
 A: Hint
Find a particular solution on the form $y(x)=axe^{ix},\;\; a\in\Bbb C$ of the differential equation
$$y''+y=e^{ix}$$and then take the imaginary part.
Edit
Substituting the particular solution in the differential equation  gives:
$$2iae^{ix}=e^{ix}$$
so we have $a=-\frac i2$ and then the imaginary part is $-\frac x2\cos x$ which 's a particular solution for the given differential equation.
A: You may use the method of variation of parameters. Since you know the solution of the homogenous part of the equation, i.e., $y(x) = A y_1 + B y_2$, with $y_1 = \cos{x} $ and $y_2 = \sin{x}$.  Assume then that the solution is given by:
$$y(x) = A(x) y_1,$$ for example (you might consider $y(x) = B(x) y_2$ or even $y(x) = A(x) y_1  + B(x) y_2 \ $!). Plug this information into the original equation to obtain:
$$ A'' y_1 + 2 A' y_1 + A y_1'' + A y_1 = \sin{x} \ \Rightarrow \  y_1 A'' + 2 y_1' A' + A \underbrace{(y_1 '' + y_1 )}_{=0} =  \sin{x}, $$ so we come up with an equation for $A$, provided that $y_1 \neq 0$: 
$$ A'' + \frac{2 y_1'}{y_1} A' = \frac{\sin{x}}{y_1} \Rightarrow \frac{d}{dx}\left(y_1^2A' \right) = y_1 \sin{x}.$$ Solve now for $A(x)$ and do not forget about the constants of integration so, after further simplifications, you will obtain the solution of the original equation in the form:
$$y(x ) = \alpha \, y_1 + \beta\, y_2 + y_p, $$ where $y_p$ is your desired particular integral of the ODE and $\alpha$ and $\beta$ are constants.
Cheers!
A: $\newcommand{\+}{^{\dagger}}
 \newcommand{\angles}[1]{\left\langle\, #1 \,\right\rangle}
 \newcommand{\braces}[1]{\left\lbrace\, #1 \,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\, #1 \,\right\rbrack}
 \newcommand{\ceil}[1]{\,\left\lceil\, #1 \,\right\rceil\,}
 \newcommand{\dd}{{\rm d}}
 \newcommand{\down}{\downarrow}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\expo}[1]{\,{\rm e}^{#1}\,}
 \newcommand{\fermi}{\,{\rm f}}
 \newcommand{\floor}[1]{\,\left\lfloor #1 \right\rfloor\,}
 \newcommand{\half}{{1 \over 2}}
 \newcommand{\ic}{{\rm i}}
 \newcommand{\iff}{\Longleftrightarrow}
 \newcommand{\imp}{\Longrightarrow}
 \newcommand{\isdiv}{\,\left.\right\vert\,}
 \newcommand{\ket}[1]{\left\vert #1\right\rangle}
 \newcommand{\ol}[1]{\overline{#1}}
 \newcommand{\pars}[1]{\left(\, #1 \,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\pp}{{\cal P}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\vphantom{\large A}\,#2\,}\,}
 \newcommand{\sech}{\,{\rm sech}}
 \newcommand{\sgn}{\,{\rm sgn}}
 \newcommand{\totald}[3][]{\frac{{\rm d}^{#1} #2}{{\rm d} #3^{#1}}}
 \newcommand{\ul}[1]{\underline{#1}}
 \newcommand{\verts}[1]{\left\vert\, #1 \,\right\vert}
 \newcommand{\wt}[1]{\widetilde{#1}}$
With $\ds{y' \equiv z}$:
\begin{align}
{y'\choose z'} - \ic\
\overbrace{\pars{\begin{array}{cc}0 & -\ic\\ \ic & 0\end{array}}}
^{\ds{\color{#c00000}{\equiv A}}}\ {y \choose z}
={0 \choose \sin\pars{x}}
\quad\imp\quad\totald{}{x}\bracks{\expo{-\ic Ax}{y \choose z}}
=\expo{-\ic Ax}{0 \choose \sin\pars{x}}
\end{align}

$$
\expo{-\ic Ax}{{\rm y}\pars{x} \choose {\rm z}\pars{x}}
=\int\expo{-\ic Ax}{0 \choose \sin\pars{x}}\,\dd x + {\bf u}\,,\quad
{\bf u} = \mbox{constant vector.}
$$

Since $\ds{A^{2} = \mbox{identity}}$,
$\ds{\expo{-\ic Ax}=\cos\pars{x} -\ic\sin\pars{x}A
=\pars{\begin{array}{cc}\cos\pars{x} & -\sin\pars{x}\\ \sin\pars{x}&\cos\pars{x}\end{array}}}$

$$
\expo{-\ic Ax}{{\rm y}\pars{x} \choose {\rm z}\pars{x}}
=\int{-\sin^{2}\pars{x} \choose \sin\pars{2x}/2}\,\dd x + {\bf u}
={1 \over 4}{\sin\pars{2x} - 2x \choose -\cos\pars{2x}} + {\bf u}
$$

\begin{align}
{\rm y}\pars{x}&
={1 \over 4}\braces{\cos\pars{x}\bracks{\sin\pars{2x} - 2x} + \sin\pars{x}\cos\pars{2x}} + {\bf u}_{1}\cos\pars{x} - {\bf u}_{2}\sin\pars{x}
\end{align}

$$\color{#00f}{\large%
{\rm y}\pars{x}
={1 \over 4}\bracks{\sin\pars{3x} - 2x\cos\pars{2x}}
+{\bf u}_{1}\cos\pars{x}
- {\bf u}_{2}\sin\pars{x}}
$$
  $\ds{{\bf u}_{1}}$ and $\ds{{\bf u}_{2}}$ are constants to be determined by the 'initial conditions'.

$\large\tt\mbox{Another Simple Method:}$
Define $\ds{\xi \equiv y' + \ic y}$ such that $\ds{y'' + y = \xi' - \ic\xi}$
and $\ds{y = \Im\xi}$. In this way, we just have to solve a first order equation:
$$
\xi' - \ic\xi=\sin\pars{x}\quad\imp\totald{\pars{\expo{-\ic x}\xi}}{x}
= \expo{-\ic x}\sin\pars{x} = \half\ic\pars{\expo{-2\ic x} - 1}
$$
