How to solve two point boundary value problem $ y'' + 2y = -x$ How to solve this differential equation $y'' + 2y = -x$ ?
I started with $y(x)= c1 \cos(\sqrt(2)x) + c2 \sin(\sqrt(2)x)$, but i think i need to put some $Yp(x)$ for $-x$ inside the equation but I do not know how.
$y'(1) = 0$ and $y(0) = 0$.
 A: Hints:

*

*The roots of the homogeneous equation are $\pm ~i~ \sqrt{2}$ (which you have).


*Using the method of Undetermined Coefficients, choose $y_p = a + bx$ and substitute back into ODE, solve for the constants. From this we find:
$$y_p(x) = a + bx, y'_p(x) = b, y''_p(x) = 0$$
Substitute those into the ODE and you end up with $2(a+bx) = -x$. By inspection, you get $a=0$ and $b = -\dfrac{1}{2}$.

*

*Your solution will be:

$$y(x) = y_h(x) + y_p(x) =  c_1 \cos(\sqrt{2}x) + c_2 \sin(\sqrt{2}x) -\dfrac{x}{2}$$

*

*Use the initial conditions to finish it off by solving for $c_1$ and $c_2$.

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{\ds}[1]{\displaystyle{#1}}%
 \newcommand{\equalby}[1]{{#1 \atop {= \atop \vphantom{\huge A}}}}%
 \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]{\,#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{\yy}{{\rm y}}$
$\ds{\yy''\pars{x} + 2\yy\pars{x} = -x\,,\quad\yy\pars{0}\,,\quad\yy'\pars{1} = 0}$.

Let's define $\ds{\xi \equiv \yy' + \ic\root{2}\yy}$ such that
$\ds{\yy'' + 2y = \xi' - \ic\root{2}\xi}$. We have to solve:
$$
\xi'\pars{x} - \ic\root{2}\xi\pars{x} = - x\quad\mbox{where}\quad\yy\pars{x} = {\root{2} \over 2}\,\Im\xi\pars{x}
$$
$$
\totald{\bracks{\expo{-\ic\root{2}x}\xi\pars{x}}}{x} = -x\expo{-\ic\root{2}x}\
\imp
\expo{-\ic\root{2}x}\xi\pars{x} = -
\overbrace{\int x\expo{-\ic\root{2}x}\,\dd x}
^{\expo{-\ic\root{2}x}\pars{1 + \ic\root{2}x}/2} + a + b\ic
$$
where $a, b$ are constants. $a, b \in {\mathbb R}$.
$$
\xi\pars{x} = -\,\half\pars{1 + \ic\root{2}x} + \pars{a + b\ic}\expo{\ic\root{2}x}
$$ 
$$
\yy\pars{x} = {\root{2} \over 2}\bracks{%
-\,{\root{2} \over 2}\,x + a\sin\pars{\root{2}x} + b\cos\pars{\root{2}x}}
$$
$\yy\pars{0} = 0\quad\imp\quad b = 0\quad\imp\quad
\ds{\yy\pars{x} = -\,\half\,x + {\root{2} \over 2}\,a\sin\pars{\root{2}x}}$
$$
\yy'\pars{x} = -\,\half + a\cos\pars{\root{2}x}\,,\quad
0 = \yy'\pars{1} = -\,\half + a\cos\pars{\root{2}}\ \imp\
a = \half\sec\pars{\root{2}}
$$

$$\color{#0000ff}{\large%
\yy\pars{x} = -\,\half\,x + {\root{2} \over 4}\,\sec\pars{\root{2}}\sin\pars{\root{2}x}} 
$$
