TITLE: Solve the boundary value problem $y''+y= -1$, $\,y(0)=y(\pi/2)=0$ with the Green's function method
QUESTION [6 upvotes]: Using the Green's Function method solve the boundary value problem:
$$ y''+ y= -1,$$  
with boundary conditions
$$y(0)=0, \quad y(\pi/2)=0.$$
Verify the result by elementary technique.

REPLY [3 votes]: $\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}$
$\ds{{\rm y}''\pars{x} + {\rm y}\pars{x} = -1\,,
\quad{\rm y}\pars{0} = {\rm y}\pars{\pi \over 2} = 0}$.

The solution is given by
$$
{\rm y}\pars{x}
= {\rm y_{p}}\pars{x} + \int_{0}^{\pi/2}{\rm G}\pars{x,x'}\pars{-1}\,\dd x'
$$
where ${\rm y_{p}}\pars{x}$ is a $\it\mbox{particular solution}$
$\ds{\pars{~{\rm y}''_{\rm p}\pars{x} + {\rm y_{p}}\pars{x} = 0~}}$ which satisfies the boundary conditions $\ds{{\rm y}\pars{0} = {\rm y}\pars{\pi \over 2} = 0}$. Obviously, $\ds{{\rm y_{p}}\pars{x} = 0\,,\forall x}$. Then
\begin{align}
{\rm y}\pars{x} &= -\int_{0}^{\pi/2}{\rm G}\pars{x,x'}\,\dd x'
\\[3mm]
-1 = {\rm y}''\pars{x} + {\rm y}\pars{x}
&=
-\int_{0}^{\pi/2}\pars{\partiald[2]{}{x} + 1}{\rm G}\pars{x,x'}\,\dd x
\end{align}
$$
\pars{\partiald[2]{}{x} + 1}{\rm G}\pars{x,x'} = \delta\pars{x - x'}\,,\qquad
\left\vert%
\begin{array}{rcl}
{\rm G}\pars{0,x'} & = & 0
\\
{\rm G}\pars{{\pi \over 2},x'} & = & 0
\end{array}\right.\tag{1}
$$
$\pars{1}$ and the continuity at $x = x'$ are equivalent to
$$
\!\!\!\!\!\!\!\!\!\!{\rm G}\pars{x,x'} =
\braces{%
\begin{array}{rcl}
A\sin\pars{x} & \mbox{if} & x < x'
\\[1mm]
B\cos\pars{x} & \mbox{if} & x > x'
\end{array}}
\quad\mbox{and}\quad\left\lbrace%
\begin{array}{rcl}
{\rm G}\pars{x'^{-},x'} & = & {\rm G}\pars{x'^{+},x'}
\\[2mm]
\left.\partiald{{\rm G}\pars{t,t'}}{t}\right\vert_{x\ =\ x'^{-}}^{x\ =\ x'^{+}}
& = & 1
\end{array}\right.\tag{2}
$$
With $\pars{2}$, we get:
$$
\left\lbrace%
\begin{array}{rcrcl}
\sin\pars{x'}A & - & \cos\pars{x'}B & = & 0
\\
-\cos\pars{x'}A & - & \sin\pars{x'}B & = & 1
\end{array}\right.
\quad\imp\quad
\left\lbrace%
\begin{array}{rcl}
A & = & -\cos\pars{x'}
\\
B & = & -\sin\pars{x'}
\end{array}\right.
$$
\begin{align}
{\rm y}\pars{x}&=-\int_{0}^{x}\bracks{-\sin\pars{x'}\cos\pars{x}}\,\dd x'
-\int_{x}^{\pi/2}\bracks{-\cos\pars{x'}\sin\pars{x}}\,\dd x'
\\[3mm]&=\cos\pars{x}\bracks{-\cos\pars{x} + 1} + \sin\pars{x}\bracks{1 -\sin\pars{x}}
\end{align}

$$\color{#0000ff}{\large%
{\rm y}\pars{x}
=
\sin\pars{x} + \cos\pars{x} - 1}
$$