% =============================================================================
% ch11_boundary_value_problems.tex
% Chapter 11: Boundary Value Problems
% =============================================================================

\section{Boundary Value Problems}
\label{ch:boundary_value_problems}

\subsection{BVP vs IVP}
\label{sec:ch11_bvp_vs_ivp}

In the preceding chapters we have focused almost exclusively on \textbf{initial value problems (IVPs)}: a differential equation together with conditions specified at a \emph{single} point. For example,
\[
  y'' + p(x)y' + q(x)y = f(x),
  \qquad y(x_0) = y_0,\; y'(x_0) = y_0'.
\]
An IVP asks: given the state of a system at one instant, what will it do in the future? This is the natural framework for time-evolution problems.

A \textbf{boundary value problem (BVP)}, by contrast, prescribes conditions at \emph{two different points} of the independent variable:
\[
  y'' + p(x)y' + q(x)y = f(x),
  \qquad y(a) = \alpha,\; y(b) = \beta,
\]
where $a \neq b$. Instead of ``initial'' conditions at a starting time, we impose \textbf{boundary conditions} at the endpoints of an interval. The independent variable $x$ typically represents spatial position rather than time.

\paragraph{When BVPs arise.} Boundary value problems appear whenever a physical quantity is constrained at the boundaries of a spatial domain. Classic examples include:
\begin{itemize}
  \item The displacement $y(x)$ of a string fixed at both ends: $y(0) = 0$, $y(L) = 0$.
  \item The temperature $u(x)$ in a rod whose ends are held at prescribed temperatures.
  \item The electric potential between two conducting plates.
\end{itemize}
In all of these, the differential equation describes the internal physics, while the boundary conditions encode the geometry or external constraints.

\paragraph{Key differences from IVPs.} Unlike IVPs, BVPs do \emph{not} always have a solution, and when a solution exists it may not be unique. The three possibilities are:
\begin{enumerate}
  \item \textbf{Unique solution}: exactly one function satisfies both the ODE and the boundary conditions.
  \item \textbf{No solution}: the boundary conditions are incompatible with any solution of the ODE.
  \item \textbf{Infinitely many solutions}: the boundary conditions are satisfied by a whole family of solutions. This occurs precisely when the associated \textbf{homogeneous BVP} admits nontrivial solutions---a phenomenon we explore in the next subsection.
\end{enumerate}

\begin{workedexample}
  Solve the BVP $y'' + y = 0$, $y(0) = 0$, $y(\pi) = 0$.

  \textbf{Solution.} The general solution of the ODE is
  \[
    y(x) = c_1 \cos x + c_2 \sin x.
  \]
  Apply the first boundary condition:
  \[
    y(0) = c_1 \cdot 1 + c_2 \cdot 0 = c_1 = 0,
  \]
  so $c_1 = 0$ and $y(x) = c_2 \sin x$.

  Apply the second boundary condition:
  \[
    y(\pi) = c_2 \sin \pi = c_2 \cdot 0 = 0.
  \]
  This condition is satisfied for \emph{any} $c_2$. Hence we have infinitely many solutions:
  \[
    y(x) = c_2 \sin x, \qquad c_2 \in \R.
  \]
  The homogeneous BVP admits nontrivial solutions; this is the hallmark of an \textbf{eigenvalue problem}.
\end{workedexample}

\begin{workedexample}
  Solve the BVP $y'' + y = 0$, $y(0) = 0$, $y(\pi/2) = 1$.

  \textbf{Solution.} Again the general solution is $y(x) = c_1 \cos x + c_2 \sin x$.

  Apply $y(0) = 0$: we obtain $c_1 = 0$, so $y(x) = c_2 \sin x$.

  Apply $y(\pi/2) = 1$:
  \[
    y(\pi/2) = c_2 \sin(\pi/2) = c_2 \cdot 1 = 1 \quad\Longrightarrow\quad c_2 = 1.
  \]
  The solution is unique: $y(x) = \sin x$.
\end{workedexample}

\subsection{Eigenvalue Problems}
\label{sec:ch11_eigenvalue_problems}

The phenomenon of infinitely many solutions leads us to one of the most important structures in applied mathematics: the \textbf{eigenvalue problem}.

Consider the second-order equation
\begin{equation}
  \label{eq:eigenvalue_problem}
  y'' + \lambda y = 0, \qquad 0 < x < L,
\end{equation}
with Dirichlet boundary conditions
\begin{equation}
  \label{eq:dirichlet_bc}
  y(0) = 0, \qquad y(L) = 0.
\end{equation}
Here $\lambda$ is a parameter. For most values of $\lambda$, the only solution is the trivial one $y \equiv 0$. But for certain special values of $\lambda$---called \textbf{eigenvalues}---there exist nontrivial solutions, called \textbf{eigenfunctions}.

\paragraph{Case analysis.} We treat three cases for the sign of $\lambda$.

\medskip
\noindent\textbf{Case 1: $\lambda < 0$.} Let $\lambda = -\mu^2$ with $\mu > 0$. The general solution is
\[
  y(x) = c_1 e^{\mu x} + c_2 e^{-\mu x}
  = A \cosh(\mu x) + B \sinh(\mu x).
\]
Apply $y(0) = 0$: $A = 0$, so $y(x) = B \sinh(\mu x)$.

Apply $y(L) = 0$: $B \sinh(\mu L) = 0$. Since $\mu > 0$ and $L > 0$, we have $\sinh(\mu L) > 0$, so $B = 0$. Hence $y \equiv 0$. There are \emph{no} eigenvalues with $\lambda < 0$.

\medskip
\noindent\textbf{Case 2: $\lambda = 0$.} The equation becomes $y'' = 0$, with general solution
\[
  y(x) = c_1 x + c_2.
\]
Apply $y(0) = 0$: $c_2 = 0$. Apply $y(L) = 0$: $c_1 L = 0$, so $c_1 = 0$. Again $y \equiv 0$. The value $\lambda = 0$ is \emph{not} an eigenvalue.

\medskip
\noindent\textbf{Case 3: $\lambda > 0$.} Let $\lambda = \mu^2$ with $\mu > 0$. The general solution is
\[
  y(x) = c_1 \cos(\mu x) + c_2 \sin(\mu x).
\]
Apply $y(0) = 0$: $c_1 = 0$, so $y(x) = c_2 \sin(\mu x)$.

Apply $y(L) = 0$: $c_2 \sin(\mu L) = 0$. For a nontrivial solution we need $c_2 \neq 0$, which requires
\[
  \sin(\mu L) = 0 \quad\Longrightarrow\quad \mu L = n\pi, \qquad n = 1, 2, 3, \dots
\]
Thus $\mu_n = \dfrac{n\pi}{L}$ and $\lambda_n = \mu_n^2 = \left(\dfrac{n\pi}{L}\right)^2$.

\begin{keyresult}
  \textbf{Dirichlet eigenvalue problem.} For
  \[
    y'' + \lambda y = 0, \qquad y(0) = 0, \;\; y(L) = 0,
  \]
  the eigenvalues and eigenfunctions are
  \[
    \lambda_n = \left(\frac{n\pi}{L}\right)^{\!2},
    \qquad
    y_n(x) = \sin\!\left(\frac{n\pi x}{L}\right),
    \qquad n = 1, 2, 3, \dots
  \]
  Any positive constant multiple of $y_n(x)$ is also an eigenfunction.
\end{keyresult}

\paragraph{Neumann boundary conditions.} If instead we impose
\[
  y'(0) = 0, \qquad y'(L) = 0,
\]
the analysis changes slightly. With $\lambda = \mu^2 > 0$, we have $y(x) = c_1 \cos(\mu x) + c_2 \sin(\mu x)$ and $y'(x) = -c_1 \mu \sin(\mu x) + c_2 \mu \cos(\mu x)$.

Apply $y'(0) = 0$: $c_2 \mu = 0$, so $c_2 = 0$. Then $y(x) = c_1 \cos(\mu x)$ and $y'(x) = -c_1 \mu \sin(\mu x)$.

Apply $y'(L) = 0$: $-c_1 \mu \sin(\mu L) = 0$. For nontrivial solutions ($c_1 \neq 0$), we need $\sin(\mu L) = 0$, so $\mu L = n\pi$ with $n = 0, 1, 2, \dots$.

Note that $n = 0$ gives $\mu = 0$, $\lambda_0 = 0$, and $y_0(x) = \cos(0) = 1$ (a nonzero constant). This means $\lambda_0 = 0$ \emph{is} an eigenvalue for Neumann conditions.

\begin{keyresult}
  \textbf{Neumann eigenvalue problem.} For
  \[
    y'' + \lambda y = 0, \qquad y'(0) = 0, \;\; y'(L) = 0,
  \]
  the eigenvalues and eigenfunctions are
  \[
    \lambda_n = \left(\frac{n\pi}{L}\right)^{\!2},
    \qquad
    y_n(x) = \cos\!\left(\frac{n\pi x}{L}\right),
    \qquad n = 0, 1, 2, \dots
  \]
  Note that $\lambda_0 = 0$ with eigenfunction $y_0(x) = 1$.
\end{keyresult}

\begin{workedexample}
  Find all eigenvalues and eigenfunctions of
  \[
    y'' + \lambda y = 0, \qquad y(0) = 0, \;\; y(2) = 0.
  \]

  \textbf{Solution.} Here $L = 2$. From \cref{eq:eigenvalue_problem}, the eigenvalues are
  \[
    \lambda_n = \left(\frac{n\pi}{2}\right)^{\!2} = \frac{n^2 \pi^2}{4},
    \qquad n = 1, 2, 3, \dots
  \]
  and the eigenfunctions are
  \[
    y_n(x) = \sin\!\left(\frac{n\pi x}{2}\right).
  \]
  Listing the first few:
  \begin{align*}
    \lambda_1 &= \frac{\pi^2}{4}, & y_1(x) &= \sin\!\left(\frac{\pi x}{2}\right), \\
    \lambda_2 &= \pi^2, & y_2(x) &= \sin(\pi x), \\
    \lambda_3 &= \frac{9\pi^2}{4}, & y_3(x) &= \sin\!\left(\frac{3\pi x}{2}\right).
  \end{align*}
\end{workedexample}

\begin{workedexample}
  Find all eigenvalues and eigenfunctions of
  \[
    y'' + \lambda y = 0, \qquad y'(0) = 0, \;\; y'(3) = 0.
  \]

  \textbf{Solution.} Here $L = 3$ with Neumann boundary conditions. The eigenvalues are
  \[
    \lambda_n = \left(\frac{n\pi}{3}\right)^{\!2} = \frac{n^2 \pi^2}{9},
    \qquad n = 0, 1, 2, \dots
  \]
  and the eigenfunctions are
  \[
    y_n(x) = \cos\!\left(\frac{n\pi x}{3}\right).
  \]
  The first few are:
  \begin{align*}
    \lambda_0 &= 0, & y_0(x) &= 1, \\
    \lambda_1 &= \frac{\pi^2}{9}, & y_1(x) &= \cos\!\left(\frac{\pi x}{3}\right), \\
    \lambda_2 &= \frac{4\pi^2}{9}, & y_2(x) &= \cos\!\left(\frac{2\pi x}{3}\right).
  \end{align*}
  Note that $y_0(x) = 1$ corresponds to the constant equilibrium state.
\end{workedexample}

\subsection{Sturm--Liouville Form}
\label{sec:ch11_sturm_liouville}

The eigenvalue problems we just studied are special cases of a broad and powerful framework: the \textbf{Sturm--Liouville (SL) problem}. This theory unifies eigenvalue problems, orthogonality, and series expansions.

\paragraph{General SL form.} A second-order linear ODE is in \textbf{Sturm--Liouville form} when it can be written as
\begin{equation}
  \label{eq:sl_form}
  \bigl(p(x)\,y'\bigr)' + \bigl(q(x) + \lambda\,r(x)\bigr)y = 0,
  \qquad a \leq x \leq b,
\end{equation}
where $p(x)$, $q(x)$, and $r(x)$ are given coefficient functions and $\lambda$ is the eigenvalue parameter. The function $r(x)$ is called the \textbf{weight function}.

\paragraph{Converting to SL form.} Any equation of the form
\begin{equation}
  \label{eq:general_second_order}
  P(x)\,y'' + Q(x)\,y' + R(x)\,y + \lambda\,S(x)\,y = 0
\end{equation}
can be converted to SL form by dividing by $P(x)$ and multiplying by an \textbf{integrating factor}. First divide by $P(x)$:
\[
  y'' + \frac{Q(x)}{P(x)}\,y' + \frac{R(x)}{P(x)}\,y + \lambda\,\frac{S(x)}{P(x)}\,y = 0.
\]
Multiply by the integrating factor
\[
  \mu(x) = \exp\!\left(\int \frac{Q(x)}{P(x)}\,\diff x\right).
\]
Then the first two terms combine as a derivative:
\[
  \mu(x)\,y'' + \mu(x)\,\frac{Q(x)}{P(x)}\,y' = \bigl(\mu(x)\,y'\bigr)',
\]
which is exactly the $(py')'$ structure of the SL form with $p(x) = \mu(x)$, $q(x) = \mu(x)\,\dfrac{R(x)}{P(x)}$, and $r(x) = \mu(x)\,\dfrac{S(x)}{P(x)}$.

\paragraph{Regular SL problem.} We restrict attention to the \textbf{regular} case:

\begin{definition}[Regular Sturm--Liouville Problem]
  \label{def:regular_sl}
  A Sturm--Liouville problem is \textbf{regular} on $[a,b]$ if:
  \begin{enumerate}
    \item $p(x)$, $p'(x)$, $q(x)$, and $r(x)$ are continuous on $[a,b]$.
    \item $p(x) > 0$ and $r(x) > 0$ on $[a,b]$.
    \item The boundary conditions are of the form
      \[
        \alpha_1 y(a) + \alpha_2 y'(a) = 0,
        \qquad
        \beta_1 y(b) + \beta_2 y'(b) = 0,
      \]
      where $\alpha_1^2 + \alpha_2^2 > 0$ and $\beta_1^2 + \beta_2^2 > 0$.
  \end{enumerate}
\end{definition}

\begin{theorem}[SL Existence Theorem]
  \label{thm:sl_existence}
  A regular Sturm--Liouville problem has:
  \begin{enumerate}
    \item An infinite sequence of real eigenvalues
      \[
        \lambda_1 < \lambda_2 < \lambda_3 < \cdots \to \infty.
      \]
    \item Each eigenvalue $\lambda_n$ has exactly one corresponding eigenfunction $\phi_n(x)$ (up to a constant multiple).
    \item The $n$-th eigenfunction $\phi_n(x)$ has exactly $n-1$ zeros in the open interval $(a,b)$.
  \end{enumerate}
\end{theorem}

This theorem guarantees that eigenvalue problems arising from well-behaved physical systems always have a rich structure of eigenvalues and eigenfunctions.

\begin{workedexample}
  Convert the equation $x\,y'' + 2y' + \lambda\,x\,y = 0$ to Sturm--Liouville form on $[0,1]$, and identify $p(x)$, $q(x)$, and $r(x)$.

  \textbf{Solution.} Here $P(x) = x$, $Q(x) = 2$, $R(x) = 0$, and $S(x) = x$.

  Divide by $P(x) = x$:
  \[
    y'' + \frac{2}{x}\,y' + \lambda\,y = 0.
  \]

  The integrating factor is
  \[
    \mu(x) = \exp\!\left(\int \frac{2}{x}\,\diff x\right)
            = \exp(2\ln x) = x^2.
  \]

  Multiply the equation by $x^2$:
  \[
    x^2\,y'' + 2x\,y' + \lambda\,x^2\,y = 0.
  \]
  The first two terms combine as
  \[
    x^2 y'' + 2x y' = (x^2 y')'.
  \]
  Hence the SL form is
  \[
    (x^2 y')' + \lambda\,x^2\,y = 0.
  \]
  Reading off the coefficients:
  \[
    p(x) = x^2, \qquad q(x) = 0, \qquad r(x) = x^2.
  \]
  On $(0,1]$, we have $p(x) = x^2 > 0$ and $r(x) = x^2 > 0$. Note that $p(0) = 0$, so strictly speaking this is a \emph{singular} SL problem (not regular) at $x = 0$, since the regularity condition requires $p > 0$ on the \emph{closed} interval. Singular SL problems require additional care at the singular endpoint.
\end{workedexample}

\subsection{Orthogonality Theorem}
\label{sec:ch11_orthogonality_theorem}

The most powerful consequence of the Sturm--Liouville framework is the \textbf{orthogonality} of eigenfunctions belonging to distinct eigenvalues.

\begin{theorem}[SL Orthogonality Theorem]
  \label{thm:sl_orthogonality}
  Let $\phi_n(x)$ and $\phi_m(x)$ be eigenfunctions corresponding to distinct eigenvalues $\lambda_n \neq \lambda_m$ of a regular Sturm--Liouville problem on $[a,b]$. Then $\phi_n$ and $\phi_m$ are \textbf{orthogonal with respect to the weight function} $r(x)$:
  \[
    \int_a^b \phi_n(x)\,\phi_m(x)\,r(x)\,\diff x = 0, \qquad n \neq m.
  \]
\end{theorem}

\begin{proof}
  The eigenfunctions satisfy the SL equations
  \[
    \begin{cases}
      \bigl(p\,\phi_n'\bigr)' + \bigl(q + \lambda_n\,r\bigr)\phi_n = 0, \\[4pt]
      \bigl(p\,\phi_m'\bigr)' + \bigl(q + \lambda_m\,r\bigr)\phi_m = 0.
    \end{cases}
  \]
  Multiply the first equation by $\phi_m(x)$ and the second by $\phi_n(x)$:
  \[
    \begin{cases}
      \phi_m\,(p\,\phi_n')' + \phi_m\,q\,\phi_n + \lambda_n\,\phi_m\,r\,\phi_n = 0, \\[4pt]
      \phi_n\,(p\,\phi_m')' + \phi_n\,q\,\phi_m + \lambda_m\,\phi_n\,r\,\phi_m = 0.
    \end{cases}
  \]
  Subtract the second from the first:
  \[
    \phi_m\,(p\,\phi_n')' - \phi_n\,(p\,\phi_m')'
    + (\lambda_n - \lambda_m)\,\phi_n\,\phi_m\,r = 0.
  \]
  The terms involving $q(x)$ cancel. Rearrange:
  \[
    (\lambda_n - \lambda_m)\,\phi_n(x)\,\phi_m(x)\,r(x)
    = \phi_n\,(p\,\phi_m')' - \phi_m\,(p\,\phi_n')'.
  \]
  The right-hand side can be written as a total derivative:
  \[
    \phi_n\,(p\,\phi_m')' - \phi_m\,(p\,\phi_n')'
    = \frac{\diff}{\diff x}\Bigl[p\bigl(\phi_n\,\phi_m' - \phi_m\,\phi_n'\bigr)\Bigr].
  \]
  To verify this, differentiate the expression inside the brackets:
  \[
    \frac{\diff}{\diff x}\Bigl[p(\phi_n\phi_m' - \phi_m\phi_n')\Bigr]
    = p'(\phi_n\phi_m' - \phi_m\phi_n') + p(\phi_n'\phi_m' + \phi_n\phi_m'' - \phi_m'\phi_n' - \phi_m\phi_n'')
    = \phi_n(p\phi_m')' - \phi_m(p\phi_n')',
  \]
  as claimed. Now integrate both sides from $a$ to $b$:
  \[
    (\lambda_n - \lambda_m)\int_a^b \phi_n(x)\,\phi_m(x)\,r(x)\,\diff x
    = \Bigl[p(x)\bigl(\phi_n(x)\,\phi_m'(x) - \phi_m(x)\,\phi_n'(x)\bigr)\Bigr]_{x=a}^{x=b}.
  \]
  The right-hand side consists of \textbf{boundary terms}. For a regular SL problem, the boundary conditions are of the form
  \[
    \alpha_1 y(a) + \alpha_2 y'(a) = 0, \qquad \beta_1 y(b) + \beta_2 y'(b) = 0.
  \]
  Both $\phi_n$ and $\phi_m$ satisfy these boundary conditions. It is a standard verification that under any such separated boundary conditions, the boundary expression
  \[
    p\bigl(\phi_n\phi_m' - \phi_m\phi_n'\bigr)
  \]
  vanishes at both $x = a$ and $x = b$. (For example, if Dirichlet conditions $y(a) = 0$ apply, then $\phi_n(a) = \phi_m(a) = 0$ makes the expression zero immediately. For mixed conditions, a short algebraic argument shows cancellation.)

  Therefore the right-hand side is zero. Since $\lambda_n \neq \lambda_m$, we divide by $(\lambda_n - \lambda_m)$ to obtain
  \[
    \int_a^b \phi_n(x)\,\phi_m(x)\,r(x)\,\diff x = 0,
  \]
  completing the proof.
\end{proof}

\paragraph{Orthogonality in action.} The orthogonality of $\{\sin(n\pi x/L)\}$ on $[0,L]$ is a direct consequence of \cref{thm:sl_orthogonality}. For the Dirichlet problem $y'' + \lambda y = 0$ on $[0,L]$, we have $p = 1$, $q = 0$, $r = 1$, and $\phi_n(x) = \sin(n\pi x/L)$. The theorem guarantees
\[
  \int_0^L \sin\!\left(\frac{n\pi x}{L}\right)\sin\!\left(\frac{m\pi x}{L}\right)\diff x = 0, \qquad n \neq m,
\]
which is precisely the sine orthogonality relation used throughout Fourier analysis (\cref{ch:fourier_series}).

\begin{workedexample}
  Verify the orthogonality of $\sin(\pi x)$ and $\sin(2\pi x)$ on $[0,1]$ by direct computation.

  \textbf{Solution.} We compute
  \[
    I = \int_0^1 \sin(\pi x)\,\sin(2\pi x)\,\diff x.
  \]
  Use the product-to-sum identity $\sin A \sin B = \frac{1}{2}[\cos(A-B) - \cos(A+B)]$:
  \[
    \sin(\pi x)\sin(2\pi x) = \frac{1}{2}\bigl[\cos(-\pi x) - \cos(3\pi x)\bigr]
    = \frac{1}{2}\bigl[\cos(\pi x) - \cos(3\pi x)\bigr].
  \]
  Integrate:
  \[
    I = \frac{1}{2}\left[\frac{\sin(\pi x)}{\pi} - \frac{\sin(3\pi x)}{3\pi}\right]_0^1
      = \frac{1}{2}\left[\frac{0}{\pi} - \frac{0}{3\pi} - 0\right] = 0.
  \]
  The integral vanishes, confirming orthogonality.
\end{workedexample}

\begin{workedexample}
  Show that the eigenfunctions of $y'' + \lambda y = 0$ with Neumann conditions $y'(0) = 0$, $y'(1) = 0$ on $[0,1]$ are orthogonal with respect to the weight $r(x) = 1$.

  \textbf{Solution.} The eigenfunctions are $\phi_n(x) = \cos(n\pi x)$ for $n = 0, 1, 2, \dots$. We need to verify
  \[
    \int_0^1 \cos(n\pi x)\,\cos(m\pi x)\,\diff x = 0, \qquad n \neq m.
  \]
  Use $\cos A \cos B = \frac{1}{2}[\cos(A-B) + \cos(A+B)]$:
  \[
    \cos(n\pi x)\cos(m\pi x) = \frac{1}{2}\bigl[\cos\bigl((n-m)\pi x\bigr) + \cos\bigl((n+m)\pi x\bigr)\bigr].
  \]
  Integrate:
  \[
    \int_0^1 \cos(n\pi x)\cos(m\pi x)\,\diff x
    = \frac{1}{2}\left[\frac{\sin((n-m)\pi x)}{(n-m)\pi} + \frac{\sin((n+m)\pi x)}{(n+m)\pi}\right]_0^1.
  \]
  Since $n \neq m$ are integers, both $(n-m)\pi$ and $(n+m)\pi$ are nonzero multiples of $\pi$, so $\sin(k\pi) = 0$ for any integer $k$. The integral evaluates to $0$, confirming orthogonality.
\end{workedexample}

\subsection{Eigenfunction Expansions}
\label{sec:ch11_eigenfunction_expansions}

The orthogonality of eigenfunctions allows us to expand an arbitrary function as a series, much like a Taylor series or a Fourier series.

\begin{keyresult}
  \textbf{Eigenfunction expansion.} Let $\{\phi_n(x)\}_{n=1}^\infty$ be the eigenfunctions of a regular SL problem on $[a,b]$ with weight $r(x)$. Any piecewise smooth function $f(x)$ on $[a,b]$ can be expanded as
  \[
    f(x) = \sum_{n=1}^\infty c_n\,\phi_n(x),
  \]
  where the \textbf{expansion coefficients} are
  \begin{equation}
    \label{eq:expansion_coefficient}
    c_n = \frac{\displaystyle\int_a^b f(x)\,\phi_n(x)\,r(x)\,\diff x}
               {\displaystyle\int_a^b \phi_n(x)^2\,r(x)\,\diff x}.
  \end{equation}
  The series converges to $f(x)$ at points of continuity, and to the average $\frac{1}{2}[f(x^+) + f(x^-)]$ at points of discontinuity.
\end{keyresult}

\paragraph{Derivation of the coefficient formula.} Multiply the expansion $f(x) = \sum_{k=1}^\infty c_k \phi_k(x)$ by $\phi_n(x)\,r(x)$ and integrate over $[a,b]$:
\[
  \int_a^b f(x)\,\phi_n(x)\,r(x)\,\diff x
  = \sum_{k=1}^\infty c_k \int_a^b \phi_k(x)\,\phi_n(x)\,r(x)\,\diff x.
\]
By orthogonality, all terms in the sum vanish except $k = n$:
\[
  \int_a^b f(x)\,\phi_n(x)\,r(x)\,\diff x
  = c_n \int_a^b \phi_n(x)^2\,r(x)\,\diff x.
\]
Solving for $c_n$ gives \cref{eq:expansion_coefficient}. The denominator
\[
  \|\phi_n\|^2 = \int_a^b \phi_n(x)^2\,r(x)\,\diff x
\]
is the squared \textbf{norm} of the eigenfunction with respect to the weight $r(x)$.

\paragraph{Connection to Fourier series.} The Fourier sine series is a special case of eigenfunction expansion. Consider the SL problem with $p = 1$, $q = 0$, $r = 1$ on $[0,L]$ and Dirichlet boundary conditions. The eigenfunctions are $\phi_n(x) = \sin(n\pi x/L)$, and
\[
  \|\phi_n\|^2 = \int_0^L \sin^2\!\left(\frac{n\pi x}{L}\right)\diff x = \frac{L}{2}.
\]
The expansion formula then gives the familiar Fourier sine coefficients:
\[
  c_n = \frac{2}{L}\int_0^L f(x)\,\sin\!\left(\frac{n\pi x}{L}\right)\diff x.
\]
Similarly, the Fourier cosine series arises from the Neumann SL problem on $[0,L]$.

\begin{workedexample}
  Expand $f(x) = x$ on $[0,1]$ as a series of eigenfunctions of $y'' + \lambda y = 0$ with Dirichlet boundary conditions $y(0) = 0$, $y(1) = 0$.

  \textbf{Solution.} The eigenfunctions are $\phi_n(x) = \sin(n\pi x)$ with weight $r(x) = 1$. We need
  \[
    c_n = \frac{\displaystyle\int_0^1 x\,\sin(n\pi x)\,\diff x}
               {\displaystyle\int_0^1 \sin^2(n\pi x)\,\diff x}.
  \]
  The denominator is
  \[
    \int_0^1 \sin^2(n\pi x)\,\diff x = \frac{1}{2}.
  \]

  For the numerator, use integration by parts with $u = x$ and $\diff v = \sin(n\pi x)\,\diff x$:
  \[
    \int_0^1 x\,\sin(n\pi x)\,\diff x
    = \left[-\frac{x}{n\pi}\cos(n\pi x)\right]_0^1 + \frac{1}{n\pi}\int_0^1 \cos(n\pi x)\,\diff x.
  \]
  The boundary term gives
  \[
    -\frac{1}{n\pi}\cos(n\pi) + 0 = -\frac{(-1)^n}{n\pi} = \frac{(-1)^{n+1}}{n\pi}.
  \]
  The remaining integral is
  \[
    \frac{1}{n\pi}\left[\frac{\sin(n\pi x)}{n\pi}\right]_0^1 = 0.
  \]
  So the numerator is $\dfrac{(-1)^{n+1}}{n\pi}$.

  Therefore
  \[
    c_n = \frac{(-1)^{n+1}/(n\pi)}{1/2} = \frac{2(-1)^{n+1}}{n\pi}.
  \]
  The eigenfunction expansion is
  \[
    x = \sum_{n=1}^\infty \frac{2(-1)^{n+1}}{n\pi}\,\sin(n\pi x),
    \qquad 0 < x < 1.
  \]
  Writing out the first few terms:
  \[
    x \approx \frac{2}{\pi}\sin(\pi x) - \frac{1}{\pi}\sin(2\pi x) + \frac{2}{3\pi}\sin(3\pi x) - \cdots
  \]
\end{workedexample}

\begin{workedexample}
  Expand $f(x) = 1$ on $[0,1]$ as a series of eigenfunctions of $y'' + \lambda y = 0$ with Neumann boundary conditions $y'(0) = 0$, $y'(1) = 0$.

  \textbf{Solution.} The eigenfunctions are $\phi_n(x) = \cos(n\pi x)$ for $n = 0, 1, 2, \dots$, with weight $r(x) = 1$.

  For $n = 0$: $\phi_0(x) = 1$. The norm is
  \[
    \|\phi_0\|^2 = \int_0^1 1^2\,\diff x = 1.
  \]
  The coefficient is
  \[
    c_0 = \frac{\int_0^1 1 \cdot 1\,\diff x}{1} = 1.
  \]

  For $n \geq 1$:
  \[
    c_n = \frac{\displaystyle\int_0^1 1 \cdot \cos(n\pi x)\,\diff x}
               {\displaystyle\int_0^1 \cos^2(n\pi x)\,\diff x}
        = \frac{\left[\frac{\sin(n\pi x)}{n\pi}\right]_0^1}{1/2}
        = \frac{0}{1/2} = 0.
  \]

  The expansion is simply
  \[
    1 = 1,
  \]
  i.e., only the $n = 0$ term survives. This makes sense: the constant function is itself the $n = 0$ eigenfunction.

  As a more instructive exercise, expand $f(x) = x$ with Neumann conditions. Then for $n = 0$:
  \[
    c_0 = \frac{\int_0^1 x \cdot 1\,\diff x}{1} = \frac{1}{2}.
  \]
  For $n \geq 1$:
  \[
    c_n = \frac{\int_0^1 x\,\cos(n\pi x)\,\diff x}{1/2}.
  \]
  Integrate by parts with $u = x$, $\diff v = \cos(n\pi x)\,\diff x$:
  \[
    \int_0^1 x\cos(n\pi x)\,\diff x
    = \left[\frac{x}{n\pi}\sin(n\pi x)\right]_0^1 - \frac{1}{n\pi}\int_0^1 \sin(n\pi x)\,\diff x.
  \]
  The boundary term vanishes ($\sin(n\pi) = 0$). The remaining integral is
  \[
    -\frac{1}{n\pi}\left[-\frac{\cos(n\pi x)}{n\pi}\right]_0^1
    = \frac{1}{(n\pi)^2}\bigl(\cos(n\pi) - \cos 0\bigr)
    = \frac{(-1)^n - 1}{(n\pi)^2}.
  \]
  This is zero for even $n$ and $-\dfrac{2}{(n\pi)^2}$ for odd $n$. Therefore
  \[
    c_n = \begin{cases}
      0, & n \text{ even}, \\[6pt]
      -\dfrac{4}{(n\pi)^2}, & n \text{ odd}.
    \end{cases}
  \]
  The expansion is
  \[
    x = \frac{1}{2} - \frac{4}{\pi^2}\cos(\pi x) - \frac{4}{9\pi^2}\cos(3\pi x) - \frac{4}{25\pi^2}\cos(5\pi x) - \cdots
  \]
  This converges to $x$ on $[0,1]$.
\end{workedexample}

\subsection{Applications}
\label{sec:ch11_applications}

Eigenfunction expansions provide a powerful method for solving \textbf{nonhomogeneous} boundary value problems.

\paragraph{The nonhomogeneous SL problem.} Consider
\begin{equation}
  \label{eq:nonhomogeneous_sl}
  \bigl(p(x)\,y'\bigr)' + q(x)\,y + \lambda\,r(x)\,y = f(x),
  \qquad a < x < b,
\end{equation}
subject to homogeneous boundary conditions at $x = a$ and $x = b$. Suppose we already know the eigenfunctions $\{\phi_n(x)\}$ and eigenvalues $\{\lambda_n\}$ of the associated homogeneous problem
\[
  \bigl(p(x)\,\phi_n'\bigr)' + q(x)\,\phi_n + \lambda_n\,r(x)\,\phi_n = 0.
\]

\paragraph{Eigenfunction expansion method.} Expand both the solution $y(x)$ and the source term $f(x)$ in the eigenfunction basis:
\[
  y(x) = \sum_{n=1}^\infty c_n\,\phi_n(x), \qquad
  f(x) = \sum_{n=1}^\infty f_n\,\phi_n(x).
\]
Substitute the series for $y(x)$ into \cref{eq:nonhomogeneous_sl}:
\[
  \sum_{n=1}^\infty c_n\,\Bigl[\bigl(p\,\phi_n'\bigr)' + q\,\phi_n + \lambda\,r\,\phi_n\Bigr] = f(x).
\]
Using the homogeneous eigenvalue equation $\bigl(p\,\phi_n'\bigr)' + q\,\phi_n = -\lambda_n\,r\,\phi_n$:
\[
  \sum_{n=1}^\infty c_n\,\bigl(-\lambda_n\,r\,\phi_n + \lambda\,r\,\phi_n\bigr) = f(x).
\]
\[
  \sum_{n=1}^\infty c_n\,(\lambda - \lambda_n)\,\phi_n(x)\,r(x) = f(x).
\]
Multiply by $\phi_m(x)$ and integrate, using orthogonality:
\[
  c_m\,(\lambda - \lambda_m)\,\|\phi_m\|^2 = f_m.
\]
Therefore, provided $\lambda \neq \lambda_n$ for any $n$:
\begin{equation}
  \label{eq:nonhomogeneous_coefficient}
  c_n = \frac{f_n}{(\lambda - \lambda_n)\,\|\phi_n\|^2}
       = \frac{\displaystyle\int_a^b f(x)\,\phi_n(x)\,r(x)\,\diff x}
              {(\lambda - \lambda_n)\displaystyle\int_a^b \phi_n(x)^2\,r(x)\,\diff x}.
\end{equation}

\paragraph{Resonance.} If $\lambda = \lambda_n$ for some $n$ and the corresponding $f_n \neq 0$, there is no solution---this is the phenomenon of \textbf{resonance}. If $f_n = 0$ for that particular $n$, the coefficient $c_n$ is undetermined (infinite solutions), as discussed in the context of homogeneous BVPs.

\begin{workedexample}
  Solve the nonhomogeneous BVP
  \[
    y'' + \pi^2\,y = x, \qquad 0 < x < 1,
    \qquad y(0) = 0, \;\; y(1) = 0.
  \]

  \textbf{Solution.} The associated homogeneous problem $y'' + \lambda y = 0$ with Dirichlet BCs has eigenfunctions $\phi_n(x) = \sin(n\pi x)$ and eigenvalues $\lambda_n = n^2\pi^2$.

  Here $\lambda = \pi^2 = \lambda_1$---we are at the first eigenvalue. This raises the question of whether a solution exists. We must check the solvability condition.

  Expand the source term $f(x) = x$ in the eigenfunction basis. From the previous worked example:
  \[
    x = \sum_{n=1}^\infty \frac{2(-1)^{n+1}}{n\pi}\,\sin(n\pi x).
  \]
  So $f_n = \dfrac{2(-1)^{n+1}}{n\pi}$.

  For $n = 1$: $\lambda = \lambda_1 = \pi^2$, so the denominator $(\lambda - \lambda_1) = 0$. The coefficient $f_1 = \dfrac{2(-1)^2}{\pi} = \dfrac{2}{\pi} \neq 0$.

  Since $f_1 \neq 0$ and $\lambda = \lambda_1$, the BVP has \textbf{no solution}. The source term $f(x) = x$ has a component along the first eigenfunction, and at resonance the system cannot respond.

  To see this directly: suppose a solution $y(x)$ exists. Multiply the ODE by $\phi_1(x) = \sin(\pi x)$ and integrate:
  \[
    \int_0^1 (y'' + \pi^2 y)\sin(\pi x)\,\diff x = \int_0^1 x\sin(\pi x)\,\diff x.
  \]
  The right-hand side is $\dfrac{2}{\pi} \neq 0$. But integrating the left side by parts twice and using the boundary conditions yields zero (this is the Fredholm alternative). Contradiction: no solution exists.
\end{workedexample}

\begin{workedexample}
  Solve the nonhomogeneous BVP
  \[
    y'' + 2\pi^2\,y = \sin(\pi x), \qquad 0 < x < 1,
    \qquad y(0) = 0, \;\; y(1) = 0.
  \]

  \textbf{Solution.} Eigenvalues: $\lambda_n = n^2\pi^2$. Here $\lambda = 2\pi^2$, which is \emph{not} an eigenvalue ($\sqrt{2}\pi$ is not a multiple of $\pi$).

  Expand $f(x) = \sin(\pi x)$ in eigenfunctions. Since $\sin(\pi x) = \phi_1(x)$, the expansion is simply
  \[
    f(x) = \sin(\pi x) = 1 \cdot \phi_1(x).
  \]
  So $f_1 = \|\phi_1\|^2 = \dfrac{1}{2}$ and $f_n = 0$ for $n \neq 1$.

  The coefficients are
  \[
    c_n = \frac{f_n}{(\lambda - \lambda_n)\,\|\phi_n\|^2}.
  \]
  For $n = 1$:
  \[
    c_1 = \frac{1/2}{(2\pi^2 - \pi^2)\cdot(1/2)} = \frac{1}{\pi^2}.
  \]
  For $n \neq 1$, $f_n = 0$ so $c_n = 0$.

  The solution is
  \[
    y(x) = \frac{1}{\pi^2}\,\sin(\pi x).
  \]
  \textbf{Verification.} Compute $y'' = -\sin(\pi x)$. Then
  \[
    y'' + 2\pi^2 y = -\sin(\pi x) + 2\pi^2 \cdot \frac{1}{\pi^2}\sin(\pi x) = -\sin(\pi x) + 2\sin(\pi x) = \sin(\pi x).
  \]
  $\checkmark$ The solution satisfies the ODE and the boundary conditions.
\end{workedexample}

\subsection{Summary}
\label{sec:ch11_summary}

\begin{table}[htbp]
\centering
\caption{Eigenvalue problems and Sturm--Liouville theory}
\label{tab:ch11_summary}
\begin{tabular}{l l p{5.5cm}}
\toprule
\textbf{Concept} & \textbf{Key formula/result} \\
\midrule
BVP vs IVP & BVP: conditions at $x=a$ and $x=b$; IVP: conditions at one point \\
Dirichlet eigenvalues & $\lambda_n = (n\pi/L)^2$, $y_n(x) = \sin(n\pi x/L)$, $n = 1, 2, \dots$ \\
Neumann eigenvalues & $\lambda_n = (n\pi/L)^2$, $y_n(x) = \cos(n\pi x/L)$, $n = 0, 1, 2, \dots$ \\
SL form & $(py')' + (q + \lambda r)y = 0$ \\
Integrating factor & $\mu(x) = \exp\!\left(\int \frac{Q(x)}{P(x)}\,\diff x\right)$ \\
SL existence & Infinite real eigenvalues $\lambda_1 < \lambda_2 < \cdots \to \infty$ \\
Orthogonality & $\displaystyle\int_a^b \phi_n \phi_m\, r\,\diff x = 0$ for $n \neq m$ \\
Expansion coefficients & $\displaystyle c_n = \frac{\int_a^b f\phi_n\,r\,\diff x}{\int_a^b \phi_n^2\,r\,\diff x}$ \\
Nonhomogeneous solution & $\displaystyle c_n = \frac{f_n}{(\lambda - \lambda_n)\,\|\phi_n\|^2}$ (if $\lambda \neq \lambda_n$) \\
Resonance & If $\lambda = \lambda_n$ and $f_n \neq 0$, no solution exists \\
\bottomrule
\end{tabular}
\end{table}

\begin{hintbox}
  \textbf{Problem-solving checklist for BVPs.}
  \begin{enumerate}
    \item Identify the boundary conditions and classify (Dirichlet, Neumann, mixed).
    \item Determine the eigenvalues and eigenfunctions of the associated homogeneous problem.
    \item Verify orthogonality of eigenfunctions with respect to the weight $r(x)$.
    \item For nonhomogeneous problems, expand $f(x)$ in the eigenfunction basis.
    \item Check whether $\lambda$ coincides with any eigenvalue (resonance).
    \item If $\lambda \neq \lambda_n$ for all $n$, compute coefficients using \cref{eq:nonhomogeneous_coefficient}.
    \item If $\lambda = \lambda_n$, check the solvability condition ($f_n = 0$).
  \end{enumerate}
\end{hintbox}
