% =============================================================================
% ch10_fourier_series.tex
% Chapter 10: Fourier Series
% =============================================================================

\section{Fourier Series}
\label{ch:fourier_series}

Periodic functions appear throughout applied mathematics: from alternating currents in electrical circuits to sound waves in acoustics, from the vibrations of strings to the seasonal forcing in climate models. Fourier series provide the analytical framework for representing an arbitrary periodic function as a superposition of simple sine and cosine waves. This chapter develops the theory and computational machinery of Fourier series, then shows how they serve as a powerful tool for solving linear differential equations with periodic forcing --- a topic that will carry over into the boundary value problems of \cref{ch:boundary_value_problems} and the PDE chapters that follow.

\subsection{Fourier Coefficients}
\label{sec:ch10_fourier_coefficients}

Let $f(x)$ be a function defined on the interval $[-L, L]$ that is $2L$-periodic, meaning $f(x + 2L) = f(x)$ for all $x$. The \textbf{Fourier series} of $f$ is the trigonometric expansion
\begin{equation}
  \label{eq:fourier_series}
  f(x) = \frac{a_0}{2} + \sum_{n=1}^{\infty} \Bigl[a_n \cos\!\Bigl(\frac{n\pi x}{L}\Bigr) + b_n \sin\!\Bigl(\frac{n\pi x}{L}\Bigr)\Bigr].
\end{equation}
The constants $a_0$, $a_n$, and $b_n$ are the \textbf{Fourier coefficients}. Their explicit formulas follow from the orthogonality of the sine and cosine basis functions, which we develop in \cref{sec:ch10_orthogonality}. Here we state them as a key result.

\begin{keyresult}
  \label{key:fourier_coefficients}
  \textbf{Fourier coefficients on $[-L, L]$.} For a function $f(x)$ defined on $[-L, L]$, the Fourier coefficients are
  \begin{align}
    a_0 &= \frac{1}{L} \int_{-L}^{L} f(x)\,\diff x, \label{eq:a0_formula} \\[6pt]
    a_n &= \frac{1}{L} \int_{-L}^{L} f(x) \cos\!\Bigl(\frac{n\pi x}{L}\Bigr)\,\diff x, \quad n \ge 1, \label{eq:an_formula} \\[6pt]
    b_n &= \frac{1}{L} \int_{-L}^{L} f(x) \sin\!\Bigl(\frac{n\pi x}{L}\Bigr)\,\diff x, \quad n \ge 1. \label{eq:bn_formula}
  \end{align}
\end{keyresult}

\paragraph{Why the $a_0/2$ convention?} Writing the constant term as $a_0/2$ rather than $a_0$ ensures that the formula for $a_0$ matches the pattern for $a_n$ when $n = 0$. Indeed, $\cos(0) = 1$, so $a_0$ computed by \cref{eq:an_formula} with $n=0$ gives $(1/L)\int_{-L}^L f(x)\,\diff x$, which is exactly \cref{eq:a0_formula}. The factor $1/2$ in \cref{eq:fourier_series} then makes the average value of the series equal to $a_0/2$.

\paragraph{Worked examples.}

\begin{workedexample}
  Compute the Fourier series of the square wave
  \[
    f(x) = \begin{cases}
      1, & 0 < x < \pi, \\
      -1, & -\pi < x < 0,
    \end{cases}
  \]
  extended as a $2\pi$-periodic function.

  \textbf{Solution.} Here $L = \pi$. We compute the coefficients.

  \textit{Coefficient $a_0$:}
  \[
    a_0 = \frac{1}{\pi} \int_{-\pi}^{\pi} f(x)\,\diff x
        = \frac{1}{\pi}\left(\int_{-\pi}^0 (-1)\,\diff x + \int_0^{\pi} 1\,\diff x\right)
        = \frac{1}{\pi}\bigl(-\pi + \pi\bigr) = 0.
  \]

  \textit{Coefficients $a_n$:}
  \[
    a_n = \frac{1}{\pi}\left(\int_{-\pi}^0 (-1)\cos(nx)\,\diff x + \int_0^{\pi} 1\cdot\cos(nx)\,\diff x\right).
  \]
  Since $f(x)$ is an odd function (symmetric about the origin), the product $f(x)\cos(nx)$ is odd $\times$ even = odd. The integral of an odd function over a symmetric interval is zero, so $a_n = 0$ for all $n \ge 1$.

  \textit{Coefficients $b_n$:}
  \[
    b_n = \frac{1}{\pi}\left(\int_{-\pi}^0 (-1)\sin(nx)\,\diff x + \int_0^{\pi} 1\cdot\sin(nx)\,\diff x\right).
  \]
  Now $f(x)\sin(nx)$ is odd $\times$ odd = even, so we can simplify:
  \[
    b_n = \frac{2}{\pi} \int_0^{\pi} \sin(nx)\,\diff x
        = \frac{2}{\pi} \left[-\frac{1}{n}\cos(nx)\right]_0^{\pi}
        = \frac{2}{n\pi}\bigl(1 - \cos(n\pi)\bigr).
  \]
  Since $\cos(n\pi) = (-1)^n$, we have $1 - (-1)^n = \begin{cases} 2 & n \text{ odd} \\ 0 & n \text{ even} \end{cases}$. Therefore:
  \[
    b_n = \begin{cases}
      \dfrac{4}{n\pi}, & n \text{ odd}, \\[8pt]
      0, & n \text{ even}.
    \end{cases}
  \]

  The Fourier series is
  \[
    f(x) = \frac{4}{\pi} \sum_{k=0}^{\infty} \frac{\sin\bigl((2k+1)x\bigr)}{2k+1}
    = \frac{4}{\pi}\left(\sin x + \frac{\sin 3x}{3} + \frac{\sin 5x}{5} + \cdots\right).
  \]
  \end{workedexample}

\begin{workedexample}
  Compute the Fourier series of the sawtooth wave $f(x) = x$ on $(-\pi, \pi)$, extended as a $2\pi$-periodic function.

  \textbf{Solution.} Here $L = \pi$. The function is odd, so $a_0 = 0$ and $a_n = 0$ for all $n$.

  \textit{Coefficients $b_n$:}
  \[
    b_n = \frac{1}{\pi} \int_{-\pi}^{\pi} x \sin(nx)\,\diff x.
  \]
  The integrand is odd $\times$ odd = even, so
  \[
    b_n = \frac{2}{\pi} \int_0^{\pi} x \sin(nx)\,\diff x.
  \]
  Integrate by parts with $u = x$, $\diff v = \sin(nx)\,\diff x$:
  \[
    \int_0^{\pi} x \sin(nx)\,\diff x
    = \Bigl[-\frac{x}{n}\cos(nx)\Bigr]_0^{\pi} + \frac{1}{n}\int_0^{\pi} \cos(nx)\,\diff x.
  \]
  The boundary term gives $-\dfrac{\pi}{n}\cos(n\pi) + 0 = -\dfrac{\pi}{n}(-1)^n = \dfrac{\pi}{n}(-1)^{n+1}$. The remaining integral vanishes:
  \[
    \frac{1}{n}\int_0^{\pi} \cos(nx)\,\diff x = \frac{1}{n}\Bigl[\frac{1}{n}\sin(nx)\Bigr]_0^{\pi} = 0.
  \]
  Therefore:
  \[
    b_n = \frac{2}{\pi} \cdot \frac{\pi}{n}(-1)^{n+1} = \frac{2}{n}(-1)^{n+1}.
  \]
  The Fourier series is
  \[
    f(x) = 2\sum_{n=1}^{\infty} \frac{(-1)^{n+1}}{n} \sin(nx)
    = 2\left(\sin x - \frac{\sin 2x}{2} + \frac{\sin 3x}{3} - \cdots\right).
  \]
\end{workedexample}

\subsection{Orthogonality}
\label{sec:ch10_orthogonality}

The formulas for the Fourier coefficients \cref{eq:a0_formula}--\cref{eq:bn_formula} are derived from the \textbf{orthogonality} of the trigonometric basis functions. Two functions $\phi(x)$ and $\psi(x)$ are \textbf{orthogonal} on $[-L, L]$ if their inner product vanishes:
\[
  \int_{-L}^{L} \phi(x)\,\psi(x)\,\diff x = 0.
\]

\begin{theorem}[Orthogonality of Trigonometric Functions]
  \label{thm:orthogonality}
  For positive integers $n, m$:
  \begin{enumerate}
    \item[\textbf{(i)}] $\displaystyle \int_{-L}^{L} \cos\!\Bigl(\frac{n\pi x}{L}\Bigr)\cos\!\Bigl(\frac{m\pi x}{L}\Bigr)\,\diff x = \begin{cases} 0, & n \neq m, \\ L, & n = m \ge 1, \\ 2L, & n = m = 0. \end{cases}$

    \item[\textbf{(ii)}] $\displaystyle \int_{-L}^{L} \sin\!\Bigl(\frac{n\pi x}{L}\Bigr)\sin\!\Bigl(\frac{m\pi x}{L}\Bigr)\,\diff x = \begin{cases} 0, & n \neq m, \\ L, & n = m. \end{cases}$

    \item[\textbf{(iii)}] $\displaystyle \int_{-L}^{L} \sin\!\Bigl(\frac{n\pi x}{L}\Bigr)\cos\!\Bigl(\frac{m\pi x}{L}\Bigr)\,\diff x = 0 \quad \text{for all } n, m \ge 0.$
  \end{enumerate}
\end{theorem}

\paragraph{Proof of (i).} Use the product-to-sum identity:
\[
  \cos A \cos B = \frac{1}{2}\bigl[\cos(A-B) + \cos(A+B)\bigr].
\]
Let $A = \dfrac{n\pi x}{L}$ and $B = \dfrac{m\pi x}{L}$. Then:
\[
  \int_{-L}^{L} \cos\!\Bigl(\frac{n\pi x}{L}\Bigr)\cos\!\Bigl(\frac{m\pi x}{L}\Bigr)\,\diff x
  = \frac{1}{2}\int_{-L}^{L} \cos\!\Bigl(\frac{(n-m)\pi x}{L}\Bigr)\,\diff x
  + \frac{1}{2}\int_{-L}^{L} \cos\!\Bigl(\frac{(n+m)\pi x}{L}\Bigr)\,\diff x.
\]

If $n \neq m$, then $n-m$ is a nonzero integer, and
\[
  \int_{-L}^{L} \cos\!\Bigl(\frac{(n-m)\pi x}{L}\Bigr)\,\diff x
  = \Bigl[\frac{L}{(n-m)\pi}\sin\!\Bigl(\frac{(n-m)\pi x}{L}\Bigr)\Bigr]_{-L}^{L}
  = \frac{L}{(n-m)\pi}\bigl[\sin((n-m)\pi) - \sin(-(n-m)\pi)\bigr] = 0,
\]
since $\sin(k\pi) = 0$ for any integer $k$. Similarly, the second integral vanishes because $n+m$ is a nonzero integer.

If $n = m \ge 1$, then $n-m = 0$ and $\cos(0) = 1$:
\[
  \frac{1}{2}\int_{-L}^{L} 1\,\diff x + \frac{1}{2}\int_{-L}^{L} \cos\!\Bigl(\frac{2n\pi x}{L}\Bigr)\,\diff x
  = \frac{1}{2}(2L) + 0 = L.
\]

If $n = m = 0$, then $\cos(0)\cos(0) = 1$, and the integral is $2L$.

\paragraph{Proof of (ii).} Use $\sin A \sin B = \dfrac{1}{2}\bigl[\cos(A-B) - \cos(A+B)\bigr]$. The same analysis as above applies: both integrals vanish for $n \neq m$. For $n = m$:
\[
  \frac{1}{2}\int_{-L}^{L} 1\,\diff x - \frac{1}{2}\int_{-L}^{L} \cos\!\Bigl(\frac{2n\pi x}{L}\Bigr)\,\diff x = L - 0 = L.
\]

\paragraph{Proof of (iii).} Use $\sin A \cos B = \dfrac{1}{2}\bigl[\sin(A+B) + \sin(A-B)\bigr]$. Both terms integrate to zero since the sine of a multiple of $\pi$ is zero at the endpoints.

\paragraph{How orthogonality yields the coefficients.} Multiply both sides of \cref{eq:fourier_series} by $\cos(m\pi x/L)$ and integrate over $[-L, L]$. By orthogonality, every term in the infinite sum vanishes except the one with $n = m$:
\[
  \int_{-L}^{L} f(x)\cos\!\Bigl(\frac{m\pi x}{L}\Bigr)\,\diff x
  = a_m \int_{-L}^{L} \cos^2\!\Bigl(\frac{m\pi x}{L}\Bigr)\,\diff x
  = a_m \cdot L,
\]
which immediately gives $a_m = \dfrac{1}{L}\int_{-L}^{L} f(x)\cos(m\pi x/L)\,\diff x$. The derivation for $b_n$ is identical, using multiplication by $\sin(m\pi x/L)$ instead. Multiplying by $1$ and integrating gives $a_0$.

\subsection{Even and Odd Functions}
\label{sec:ch10_even_odd}

When $f(x)$ possesses symmetry, the Fourier series simplifies dramatically. A function is \textbf{even} if $f(-x) = f(x)$, and \textbf{odd} if $f(-x) = -f(x)$.

\begin{keyresult}
  \textbf{Fourier series of even and odd functions.}
  \begin{itemize}
    \item If $f(x)$ is \textbf{even} on $[-L, L]$, then $b_n = 0$ for all $n$, and
    \[
      a_0 = \frac{2}{L} \int_0^L f(x)\,\diff x,
      \qquad
      a_n = \frac{2}{L} \int_0^L f(x)\cos\!\Bigl(\frac{n\pi x}{L}\Bigr)\,\diff x.
    \]
    The series contains only cosine terms (a \textbf{cosine series}).

    \item If $f(x)$ is \textbf{odd} on $[-L, L]$, then $a_0 = 0$ and $a_n = 0$ for all $n$, and
    \[
      b_n = \frac{2}{L} \int_0^L f(x)\sin\!\Bigl(\frac{n\pi x}{L}\Bigr)\,\diff x.
    \]
    The series contains only sine terms (a \textbf{sine series}).
  \end{itemize}
\end{keyresult}

\paragraph{Intuition.} The product of an even function with a sine (odd) is odd, and the integral of an odd function over $[-L, L]$ is zero. Hence an even function has no sine terms. Conversely, the product of an odd function with a cosine (even) is odd, so an odd function has no cosine terms.

\paragraph{Worked examples.}

\begin{workedexample}
  Find the Fourier series of $f(x) = |x|$ on $[-\pi, \pi]$.

  \textbf{Solution.} Since $|-x| = |x|$, the function is even. We need only compute the cosine coefficients. With $L = \pi$:
  \[
    a_0 = \frac{2}{\pi}\int_0^{\pi} x\,\diff x = \frac{2}{\pi}\cdot\frac{\pi^2}{2} = \pi.
  \]
  For $n \ge 1$:
  \[
    a_n = \frac{2}{\pi}\int_0^{\pi} x\cos(nx)\,\diff x.
  \]
  Integrate by parts with $u = x$, $\diff v = \cos(nx)\,\diff x$:
  \[
    \int_0^{\pi} x\cos(nx)\,\diff x
    = \Bigl[\frac{x}{n}\sin(nx)\Bigr]_0^{\pi} - \frac{1}{n}\int_0^{\pi} \sin(nx)\,\diff x.
  \]
  The boundary term vanishes (since $\sin(n\pi) = 0$), and the remaining integral is
  \[
    -\frac{1}{n}\Bigl[-\frac{1}{n}\cos(nx)\Bigr]_0^{\pi}
    = \frac{1}{n^2}\bigl((-1)^n - 1\bigr).
  \]
  Therefore:
  \[
    a_n = \frac{2}{\pi}\cdot\frac{1}{n^2}\bigl((-1)^n - 1\bigr)
    = \begin{cases}
        0, & n \text{ even}, \\[6pt]
        -\dfrac{4}{\pi n^2}, & n \text{ odd}.
      \end{cases}
  \]
  The Fourier series is
  \[
    |x| = \frac{\pi}{2} - \frac{4}{\pi}\sum_{k=0}^{\infty} \frac{\cos\bigl((2k+1)x\bigr)}{(2k+1)^2}
    = \frac{\pi}{2} - \frac{4}{\pi}\left(\cos x + \frac{\cos 3x}{9} + \frac{\cos 5x}{25} + \cdots\right).
  \]
\end{workedexample}

\begin{workedexample}
  Find the Fourier series of $f(x) = x^2$ on $[-\pi, \pi]$.

  \textbf{Solution.} The function is even, so $b_n = 0$. With $L = \pi$:
  \[
    a_0 = \frac{2}{\pi}\int_0^{\pi} x^2\,\diff x = \frac{2}{\pi}\cdot\frac{\pi^3}{3} = \frac{2\pi^2}{3}.
  \]
  For $n \ge 1$:
  \[
    a_n = \frac{2}{\pi}\int_0^{\pi} x^2\cos(nx)\,\diff x.
  \]
  Integrate by parts twice. First, $u = x^2$, $\diff v = \cos(nx)\,\diff x$:
  \[
    \int_0^{\pi} x^2\cos(nx)\,\diff x
    = \Bigl[\frac{x^2}{n}\sin(nx)\Bigr]_0^{\pi} - \frac{2}{n}\int_0^{\pi} x\sin(nx)\,\diff x.
  \]
  The boundary term vanishes. From \cref{sec:ch10_fourier_coefficients} (sawtooth example), $\int_0^{\pi} x\sin(nx)\,\diff x = \dfrac{\pi}{n}(-1)^{n+1}$. So:
  \[
    \int_0^{\pi} x^2\cos(nx)\,\diff x = -\frac{2}{n}\cdot\frac{\pi}{n}(-1)^{n+1}
    = \frac{2\pi}{n^2}(-1)^n.
  \]
  Therefore:
  \[
    a_n = \frac{2}{\pi}\cdot\frac{2\pi}{n^2}(-1)^n = \frac{4(-1)^n}{n^2}.
  \]
  The Fourier series is
  \[
    x^2 = \frac{\pi^2}{3} + 4\sum_{n=1}^{\infty} \frac{(-1)^n}{n^2}\cos(nx)
    = \frac{\pi^2}{3} - 4\left(\frac{\cos x}{1^2} - \frac{\cos 2x}{2^2} + \frac{\cos 3x}{3^2} - \cdots\right).
  \]
\end{workedexample}

\subsection{Half-Range Expansions}
\label{sec:ch10_half_range}

In practice, a function $f(x)$ is often given only on the half-interval $[0, L]$. We can construct a Fourier series by \textbf{extending} $f$ to $[-L, L]$ as either an even function (yielding a cosine series) or an odd function (yielding a sine series). These are called \textbf{half-range expansions}.

\begin{keyresult}
  \textbf{Half-range expansions on $[0, L]$.}
  \begin{itemize}
    \item \textbf{Cosine series (even extension).} Extend $f$ to $[-L, L]$ by defining $f(-x) = f(x)$. The Fourier series contains only cosine terms:
    \[
      f(x) = \frac{a_0}{2} + \sum_{n=1}^{\infty} a_n \cos\!\Bigl(\frac{n\pi x}{L}\Bigr),
    \]
    with $a_n = \dfrac{2}{L} \int_0^L f(x)\cos\!\Bigl(\dfrac{n\pi x}{L}\Bigr)\,\diff x$ for $n \ge 0$.

    \item \textbf{Sine series (odd extension).} Extend $f$ to $[-L, L]$ by defining $f(-x) = -f(x)$. The Fourier series contains only sine terms:
    \[
      f(x) = \sum_{n=1}^{\infty} b_n \sin\!\Bigl(\frac{n\pi x}{L}\Bigr),
    \]
    with $b_n = \dfrac{2}{L} \int_0^L f(x)\sin\!\Bigl(\dfrac{n\pi x}{L}\Bigr)\,\diff x$.
  \end{itemize}
\end{keyresult}

\paragraph{Worked examples.}

\begin{workedexample}
  Find the half-range cosine series for $f(x) = x$ on $[0, \pi]$.

  \textbf{Solution.} We extend $f(x) = x$ on $[0, \pi]$ to an even function on $[-\pi, \pi]$. With $L = \pi$:
  \[
    a_0 = \frac{2}{\pi}\int_0^{\pi} x\,\diff x = \frac{2}{\pi}\cdot\frac{\pi^2}{2} = \pi.
  \]
  For $n \ge 1$:
  \[
    a_n = \frac{2}{\pi}\int_0^{\pi} x\cos(nx)\,\diff x.
  \]
  This is the same integral as in \cref{sec:ch10_even_odd}:
  \[
    a_n = \frac{2}{\pi}\cdot\frac{1}{n^2}\bigl((-1)^n - 1\bigr)
    = \begin{cases}
        0, & n \text{ even}, \\[6pt]
        -\dfrac{4}{\pi n^2}, & n \text{ odd}.
      \end{cases}
  \]
  The half-range cosine series is
  \[
    x = \frac{\pi}{2} - \frac{4}{\pi}\sum_{k=0}^{\infty} \frac{\cos\bigl((2k+1)x\bigr)}{(2k+1)^2}
    \qquad \text{for } x \in [0, \pi].
  \]
  Note: this series actually represents the \emph{even} extension $|x|$ on $[-\pi, \pi]$. On $[0, \pi]$, $|x| = x$, so the equality holds.
\end{workedexample}

\begin{workedexample}
  Find the half-range sine series for $f(x) = 1$ on $[0, \pi]$.

  \textbf{Solution.} We extend $f(x) = 1$ on $[0, \pi]$ to an odd function on $[-\pi, \pi]$. With $L = \pi$:
  \[
    b_n = \frac{2}{\pi}\int_0^{\pi} 1\cdot\sin(nx)\,\diff x
        = \frac{2}{\pi}\Bigl[-\frac{1}{n}\cos(nx)\Bigr]_0^{\pi}
        = \frac{2}{n\pi}\bigl(1 - (-1)^n\bigr).
  \]
  This is nonzero only for odd $n$:
  \[
    b_n = \begin{cases}
      \dfrac{4}{n\pi}, & n \text{ odd}, \\[8pt]
      0, & n \text{ even}.
    \end{cases}
  \]
  The half-range sine series is
  \[
    1 = \frac{4}{\pi}\sum_{k=0}^{\infty} \frac{\sin\bigl((2k+1)x\bigr)}{2k+1}
    = \frac{4}{\pi}\left(\sin x + \frac{\sin 3x}{3} + \frac{\sin 5x}{5} + \cdots\right).
  \]
  This series converges to $1$ on $(0, \pi)$ but converges to $0$ at $x = 0$ and $x = \pi$ (the endpoints where the odd extension has jump discontinuities). This behavior is explained by the Dirichlet convergence theorem (\cref{sec:ch10_convergence_gibbs}).
\end{workedexample}

\subsection{Complex Fourier Series}
\label{sec:ch10_complex_fourier}

The real Fourier series \cref{eq:fourier_series} can be written more compactly using Euler's formula $e^{i\theta} = \cos\theta + i\sin\theta$. The \textbf{complex Fourier series} is
\begin{equation}
  \label{eq:complex_fourier}
  f(x) = \sum_{n=-\infty}^{\infty} c_n\,e^{i n\pi x / L},
\end{equation}
where the \textbf{complex Fourier coefficients} are
\begin{equation}
  \label{eq:complex_coefficients}
  c_n = \frac{1}{2L}\int_{-L}^{L} f(x)\,e^{-i n\pi x / L}\,\diff x.
\end{equation}

\begin{keyresult}
  \textbf{Relationship between real and complex coefficients.}
  \begin{align}
    c_0 &= \frac{a_0}{2}, \\[6pt]
    c_n &= \frac{a_n - i b_n}{2} \quad \text{for } n > 0, \\[6pt]
    c_{-n} &= \frac{a_n + i b_n}{2} \quad \text{for } n > 0.
  \end{align}
  Equivalently, $a_n = c_n + c_{-n}$ and $b_n = i(c_n - c_{-n})$.

  If $f(x)$ is real-valued, then $c_{-n} = \overline{c_n}$ (complex conjugate).
\end{keyresult}

\paragraph{Derivation.} Substitute $e^{\pm i n\pi x / L} = \cos(n\pi x / L) \pm i\sin(n\pi x / L)$ into \cref{eq:complex_fourier}, collect real and imaginary parts, and compare with \cref{eq:fourier_series}. The reverse direction uses $a_n = c_n + c_{-n}$ and $b_n = i(c_n - c_{-n})$.

\paragraph{Worked example.}

\begin{workedexample}
  Find the complex Fourier series of $f(x) = e^{ax}$ on $[-\pi, \pi]$, where $a \in \R$.

  \textbf{Solution.} With $L = \pi$:
  \[
    c_n = \frac{1}{2\pi}\int_{-\pi}^{\pi} e^{ax}\,e^{-i n x}\,\diff x
        = \frac{1}{2\pi}\int_{-\pi}^{\pi} e^{(a - in)x}\,\diff x.
  \]
  For $n \neq 0$ (or $a \neq 0$):
  \[
    c_n = \frac{1}{2\pi}\Bigl[\frac{e^{(a-in)x}}{a - in}\Bigr]_{-\pi}^{\pi}
        = \frac{1}{2\pi(a - in)}\bigl(e^{(a-in)\pi} - e^{-(a-in)\pi}\bigr).
  \]
  Since $e^{-in\pi} = (-1)^n$ and $e^{in\pi} = (-1)^n$:
  \[
    c_n = \frac{(-1)^n}{2\pi(a - in)}\bigl(e^{a\pi} - e^{-a\pi}\bigr)
        = \frac{(-1)^n \sinh(a\pi)}{\pi(a - in)}.
  \]
  For $n = 0$:
  \[
    c_0 = \frac{1}{2\pi}\int_{-\pi}^{\pi} e^{ax}\,\diff x
        = \frac{e^{a\pi} - e^{-a\pi}}{2\pi a}
        = \frac{\sinh(a\pi)}{\pi a}.
  \]
  The complex Fourier series is
  \[
    e^{ax} = \frac{\sinh(a\pi)}{\pi}\left(\frac{1}{a} + \sum_{\substack{n=-\infty \\ n \neq 0}}^{\infty} \frac{(-1)^n}{a - in}\,e^{inx}\right).
  \]
\end{workedexample}

\subsection{Convergence and Gibbs Phenomenon}
\label{sec:ch10_convergence_gibbs}

\begin{theorem}[Dirichlet Convergence Theorem]
  \label{thm:dirichlet_convergence}
  Let $f(x)$ be $2L$-periodic and piecewise smooth on $[-L, L]$ (i.e., $f$ and $f'$ are piecewise continuous). Then the Fourier series of $f$ converges at every point $x$ to
  \[
    S(x) = \frac{f(x^+) + f(x^-)}{2},
  \]
  where $f(x^+) = \lim_{\epsilon \to 0^+} f(x+\epsilon)$ and $f(x^-) = \lim_{\epsilon \to 0^+} f(x-\epsilon)$ are the right-hand and left-hand limits. In particular, at any point where $f$ is continuous, the series converges to $f(x)$.
\end{theorem}

\paragraph{Implications.} If $f(x)$ is continuous on $[-L, L]$, its Fourier series converges pointwise to $f(x)$ everywhere. At a jump discontinuity where the function jumps from $f(x^-)$ to $f(x^+)$, the series converges to the \emph{average} of the two values.

\paragraph{Gibbs phenomenon.} Near a jump discontinuity of size $J = |f(x^+) - f(x^-)|$, the partial sums of the Fourier series exhibit a persistent overshoot: even as the number of terms $N \to \infty$, the overshoot approaches approximately
\[
  0.08949 \cdot J \quad (\text{about } 8.95\% \text{ of the jump}).
\]
This is \textbf{not} a numerical artifact; it is an inherent feature of Fourier series at discontinuities. The overshoot does \emph{not} disappear as $N$ increases --- it merely becomes more concentrated near the discontinuity.

\begin{figure}[htbp]
  \centering
  \begin{tikzpicture}[scale=1.1]
    % Axes
    \draw[->] (-1,0) -- (7,0) node[right] {$x$};
    \draw[->] (0,-1.2) -- (0,2.5) node[above] {$S_N(x)$};

    % Square wave (ideal): from 0 to 3 it is 1, from 3 to 6 it is -1
    \draw[thick, red!80, dashed] (0,1) -- (3,1);
    \draw[thick, red!80, dashed] (3,1) -- (3,-1);
    \draw[thick, red!80, dashed] (3,-1) -- (6,-1);

    % Partial sum with Gibbs overshoot
    \draw[thick, blue!80] (0,0)
      to [out=30, in=180] (1.5, 0.6)
      to [out=0, in=180] (2.3, 0.95)
      to [out=35, in=145] (2.6, 1.15)
      to [out=0, in=180] (2.85, 0.92)
      to [out=30, in=180] (2.97, 0.7)
      node[pos=0.05, above] {$S_N(x)$}
      to [out=-50, in=180] (3.03, -0.7)
      to [out=0, in=140] (3.15, -0.92)
      to [out=0, in=180] (3.4, -1.15)
      to [out=0, in=180] (3.7, -0.95)
      to [out=0, in=180] (4.5, -0.6)
      to [out=0, in=180] (6, -0.35);

    % Mark the overshoot
    \draw[thick, dashed, magenta] (2.6,1.15) -- (2.6,1) node[above, magenta, font=\small] {overshoot};
    \draw[<->, magenta, thick] (2.6,1) -- (2.6,1.15);
    \draw[<->, magenta, thick] (3.4,-1) -- (3.4,-1.15);
    \node[magenta, font=\small, anchor=west] at (3.4,-1.15) {$\approx 8.95\%$};

    % Mark the discontinuity at x=3
    \draw[dotted, gray] (3,-1.5) -- (3,1.5);
    \node[font=\small] at (3,-1.5) [anchor=north] {jump};

    % Labels
    \node[red!80, font=\small] at (6.5,1) {$f(x)$ (square wave)};
    \node[blue!80, font=\small] at (6.5,1.5) {$S_N(x)$ (partial sum)};

    % Arrow to overshoot annotation
    \draw[->, magenta] (2.6,1.15) -- ++(0.5, 0.4) node[above, magenta, font=\footnotesize] {Gibbs overshoot};
  \end{tikzpicture}
  \caption{Gibbs phenomenon: the partial sum $S_N(x)$ of a Fourier series overshoots the function value at a jump discontinuity by approximately $8.95\%$ of the jump size, even as $N \to \infty$. The dashed red line is the ideal square wave $f(x)$; the solid blue curve is the partial sum.}
  \label{fig:gibbs_phenomenon}
\end{figure}

\begin{hintbox}
  \textbf{The Gibbs constant.} The exact overshoot is $\displaystyle \frac{2}{\pi}\int_0^{\pi}\frac{\sin t}{t}\,\diff t - 1 \approx 0.08949$ times the jump size. The integral $\displaystyle \int_0^{\pi} \dfrac{\sin t}{t}\,\diff t$ is related to the \emph{sinc integral} $\operatorname{Si}(\pi) \approx 1.85194$.
\end{hintbox}

\subsection{Parseval's Identity}
\label{sec:ch10_parseval}

\begin{theorem}[Parseval's Identity]
  \label{thm:parseval}
  Let $f(x)$ have the Fourier series
  \[
    f(x) \sim \frac{a_0}{2} + \sum_{n=1}^{\infty}\Bigl[a_n\cos\!\Bigl(\frac{n\pi x}{L}\Bigr) + b_n\sin\!\Bigl(\frac{n\pi x}{L}\Bigr)\Bigr].
  \]
  Then
  \begin{equation}
    \label{eq:parseval}
    \frac{1}{L}\int_{-L}^{L} \bigl[f(x)\bigr]^2\,\diff x
    = \frac{a_0^2}{2} + \sum_{n=1}^{\infty} \bigl(a_n^2 + b_n^2\bigr).
  \end{equation}
  In words: the average energy (mean square) of the function equals the sum of the squared magnitudes of its Fourier coefficients.
\end{theorem}

\paragraph{Proof sketch.} Square the Fourier series and integrate over $[-L, L]$. By orthogonality (\cref{thm:orthogonality}), all cross-terms vanish:
\[
  \int_{-L}^{L} \cos\!\Bigl(\frac{n\pi x}{L}\Bigr)\cos\!\Bigl(\frac{m\pi x}{L}\Bigr)\,\diff x = 0 \text{ for } n \neq m,
\]
and similarly for the sine--sine and sine--cosine products. The surviving terms are:
\[
  \int_{-L}^{L} \frac{a_0^2}{4}\,\diff x = \frac{a_0^2}{4}\cdot 2L = \frac{a_0^2}{2}\cdot L,
\]
\[
  \int_{-L}^{L} a_n^2\cos^2\!\Bigl(\frac{n\pi x}{L}\Bigr)\,\diff x = a_n^2\cdot L,
\qquad
  \int_{-L}^{L} b_n^2\sin^2\!\Bigl(\frac{n\pi x}{L}\Bigr)\,\diff x = b_n^2\cdot L.
\]
Dividing the total by $L$ gives \cref{eq:parseval}.

\begin{keyresult}
  \textbf{Parseval's identity in the complex form.} For the complex Fourier coefficients $c_n$ of \cref{eq:complex_coefficients}:
  \[
    \frac{1}{2L}\int_{-L}^{L} |f(x)|^2\,\diff x = \sum_{n=-\infty}^{\infty} |c_n|^2.
  \]
\end{keyresult}

\paragraph{Application: computing infinite series.}

\begin{workedexample}
  Use Parseval's identity to evaluate $\displaystyle \sum_{n=1}^{\infty} \frac{1}{n^4}$.

  \textbf{Solution.} From \cref{sec:ch10_even_odd}, the Fourier series of $x^2$ on $[-\pi, \pi]$ is
  \[
    x^2 = \frac{\pi^2}{3} + 4\sum_{n=1}^{\infty} \frac{(-1)^n}{n^2}\cos(nx).
  \]
  Here $a_0 = \dfrac{2\pi^2}{3}$ and $a_n = \dfrac{4(-1)^n}{n^2}$, with $b_n = 0$. Parseval's identity (\cref{eq:parseval}) with $L = \pi$ gives:
  \[
    \frac{1}{\pi}\int_{-\pi}^{\pi} x^4\,\diff x = \frac{a_0^2}{2} + \sum_{n=1}^{\infty} a_n^2.
  \]
  The left side:
  \[
    \frac{1}{\pi}\int_{-\pi}^{\pi} x^4\,\diff x = \frac{2}{\pi}\int_0^{\pi} x^4\,\diff x = \frac{2}{\pi}\cdot\frac{\pi^5}{5} = \frac{2\pi^4}{5}.
  \]
  The right side:
  \[
    \frac{a_0^2}{2} = \frac{1}{2}\left(\frac{2\pi^2}{3}\right)^2 = \frac{2\pi^4}{9},
  \]
  \[
    \sum_{n=1}^{\infty} a_n^2 = \sum_{n=1}^{\infty} \frac{16}{n^4} = 16\sum_{n=1}^{\infty} \frac{1}{n^4}.
  \]
  Equating both sides:
  \[
    \frac{2\pi^4}{5} = \frac{2\pi^4}{9} + 16\sum_{n=1}^{\infty} \frac{1}{n^4}.
  \]
  Solving:
  \[
    16\sum_{n=1}^{\infty} \frac{1}{n^4} = \frac{2\pi^4}{5} - \frac{2\pi^4}{9}
    = 2\pi^4\left(\frac{1}{5} - \frac{1}{9}\right)
    = 2\pi^4\cdot\frac{4}{45}
    = \frac{8\pi^4}{45}.
  \]
  Therefore:
  \[
    \sum_{n=1}^{\infty} \frac{1}{n^4} = \frac{\pi^4}{90}.
  \]
  This is the famous result $\zeta(4) = \dfrac{\pi^4}{90}$.
\end{workedexample}

\subsection{Applications to ODEs}
\label{sec:ch10_applications_odes}

Fourier series provide a powerful method for solving linear ODEs with \textbf{periodic forcing}. The basic idea is to expand the periodic forcing function as a Fourier series, then solve the ODE for each harmonic component --- exploiting the superposition principle for linear equations.

\paragraph{General method.} Consider the forced harmonic oscillator
\begin{equation}
  \label{eq:forced_oscillator}
  x'' + \omega_0^2 x = f(t),
\end{equation}
where $f(t)$ is $2\pi$-periodic. Expand $f(t)$ as a Fourier series:
\[
  f(t) = \frac{a_0}{2} + \sum_{n=1}^{\infty}\bigl[a_n\cos(nt) + b_n\sin(nt)\bigr].
\]
By linearity, we can solve the ODE for each term separately:
\begin{enumerate}
  \item For the constant term $a_0/2$: the particular solution is $x_p = \dfrac{a_0}{2\omega_0^2}$.
  \item For each $\cos(nt)$ term: solve $x'' + \omega_0^2 x = a_n\cos(nt)$. If $n \neq \omega_0$, the particular solution is
  \[
    x_n^{(c)}(t) = \frac{a_n}{\omega_0^2 - n^2}\cos(nt).
  \]
  \item For each $\sin(nt)$ term: solve $x'' + \omega_0^2 x = b_n\sin(nt)$. If $n \neq \omega_0$,
  \[
    x_n^{(s)}(t) = \frac{b_n}{\omega_0^2 - n^2}\sin(nt).
  \]
\end{enumerate}
The full particular solution is the sum of all these mode-by-mode solutions.

\begin{remark}
  \textbf{Resonance warning.} If $n = \omega_0$ for some harmonic present in the forcing, the denominator $\omega_0^2 - n^2$ vanishes and the method breaks down. This is the phenomenon of \textbf{resonance}: the forced response grows without bound (secular growth). In this case, the particular solution takes the form
  \[
    x_p(t) = \frac{a_n}{2\omega_0} t \sin(\omega_0 t) \quad \text{or} \quad \frac{b_n}{2\omega_0} t \cos(\omega_0 t),
  \]
  producing a linearly growing amplitude. This is consistent with the theory of undetermined coefficients developed in \cref{ch:second_order_nonhomogeneous}.
\end{remark}

\begin{workedexample}
  Solve the initial value problem
  \[
    x'' + 4x = f(t), \qquad x(0) = 0, \quad x'(0) = 0,
  \]
  where $f(t)$ is the $2\pi$-periodic square wave:
  \[
    f(t) = \begin{cases}
      1, & 0 < t < \pi, \\
      -1, & \pi < t < 2\pi.
    \end{cases}
  \]

  \textbf{Solution.} From the first example in \cref{sec:ch10_fourier_coefficients}, the Fourier series of this square wave is
  \[
    f(t) = \frac{4}{\pi}\sum_{k=0}^{\infty} \frac{\sin\bigl((2k+1)t\bigr)}{2k+1}.
  \]
  Let $n_k = 2k+1$. The ODE for the $k$-th mode is
  \[
    x_k'' + 4x_k = \frac{4}{\pi n_k}\sin(n_k t).
  \]
  Since $\omega_0^2 = 4$, we have $\omega_0 = 2$. Check for resonance: $n_k = 1, 3, 5, \ldots$, and $n_k \neq 2$ for any $k$, so no resonance occurs. The particular solution for the $k$-th mode is
  \[
    x_k(t) = \frac{4/(\pi n_k)}{4 - n_k^2}\sin(n_k t)
    = \frac{4}{\pi n_k(4 - n_k^2)}\sin(n_k t).
  \]
  The complete particular solution is the sum:
  \[
    x_p(t) = \frac{4}{\pi}\sum_{k=0}^{\infty} \frac{\sin\bigl((2k+1)t\bigr)}{(2k+1)\bigl(4 - (2k+1)^2\bigr)}.
  \]
  The general solution is $x(t) = x_h(t) + x_p(t)$, where the homogeneous solution is
  \[
    x_h(t) = C_1\cos(2t) + C_2\sin(2t).
  \]
  Apply initial conditions: $x(0) = 0$ implies $C_1 + x_p(0) = 0$. Since $x_p(0) = 0$ (all sine terms vanish at $t=0$), we get $C_1 = 0$. For $x'(0) = 0$:
  \[
    x'(t) = 2C_2\cos(2t) + x_p'(t),
  \]
  and $x_p'(0) = \dfrac{4}{\pi}\sum_{k=0}^{\infty} \dfrac{1}{4 - (2k+1)^2}$. Using the closed-form sum, one finds $x_p'(0) = -\dfrac{1}{2}$. Setting $x'(0) = 2C_2 - \dfrac{1}{2} = 0$ gives $C_2 = \dfrac{1}{4}$.

  The final solution is
  \[
    x(t) = \frac{1}{4}\sin(2t) + \frac{4}{\pi}\sum_{k=0}^{\infty} \frac{\sin\bigl((2k+1)t\bigr)}{(2k+1)\bigl(4 - (2k+1)^2\bigr)}.
  \]
\end{workedexample}

\begin{hintbox}
  \textbf{Physical intuition for Fourier forcing.} Each harmonic component of the forcing drives the system at its own frequency. The system's response at frequency $n$ is amplified by the factor $\dfrac{1}{|\omega_0^2 - n^2|}$: forcing frequencies far from the natural frequency produce a small response, while forcing frequencies close to $\omega_0$ produce a large response. This frequency-selective amplification is the fundamental principle behind filters in signal processing and is why resonance is both useful (e.g., tuning a radio) and dangerous (e.g., the Tacoma Narrows Bridge collapse).
\end{hintbox}

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

Fourier series transform the study of periodic functions into the algebra of their spectral coefficients. By decomposing a periodic function into sine and cosine harmonics, we gain the ability to:
\begin{itemize}
  \item Analyze and synthesize periodic signals in engineering and physics.
  \item Solve linear ODEs and PDEs with periodic forcing or boundary conditions.
  \item Evaluate infinite series via Parseval's identity.
  \item Understand the frequency content of complex waveforms.
\end{itemize}

The Fourier series framework developed here will be directly applied in the study of boundary value problems (\cref{ch:boundary_value_problems}), the heat equation (\cref{ch:heat_equation}), and the wave and Laplace equations (\cref{ch:wave_and_laplace}), where separation of variables naturally produces Fourier expansions.

\begin{table}[htbp]
\centering
\caption{Fourier series: key formulas and concepts}
\label{tab:ch10_summary}
\begin{tabular}{l l}
\toprule
\textbf{Concept} & \textbf{Key Formula/Method} \\
\midrule
Fourier series on $[-L, L]$ &
$f(x) = \dfrac{a_0}{2} + \sum\limits_{n=1}^{\infty}\!\bigl[a_n\cos(\frac{n\pi x}{L}) + b_n\sin(\frac{n\pi x}{L})\bigr]$ \\[12pt]
Cosine coefficient $a_n$ &
$a_n = \dfrac{1}{L}\int_{-L}^{L} f(x)\cos(\frac{n\pi x}{L})\,\diff x$ \\[10pt]
Sine coefficient $b_n$ &
$b_n = \dfrac{1}{L}\int_{-L}^{L} f(x)\sin(\frac{n\pi x}{L})\,\diff x$ \\[10pt]
Even function &
$b_n = 0$, $a_n = \dfrac{2}{L}\int_0^L f(x)\cos(\frac{n\pi x}{L})\,\diff x$ \\[10pt]
Odd function &
$a_0 = a_n = 0$, $b_n = \dfrac{2}{L}\int_0^L f(x)\sin(\frac{n\pi x}{L})\,\diff x$ \\[10pt]
Complex Fourier series &
$f(x) = \sum_{n=-\infty}^{\infty} c_n e^{in\pi x/L}$, \quad
$c_n = \dfrac{1}{2L}\int_{-L}^{L} f(x)e^{-in\pi x/L}\,\diff x$ \\[10pt]
Dirichlet convergence &
Series converges to $\dfrac{f(x^+) + f(x^-)}{2}$ at every $x$ \\[8pt]
Gibbs overshoot &
$\approx 8.95\%$ of jump at discontinuity, persists as $N \to \infty$ \\[8pt]
Parseval's identity &
$\dfrac{1}{L}\int_{-L}^{L} f(x)^2\,\diff x = \dfrac{a_0^2}{2} + \sum_{n=1}^{\infty}(a_n^2 + b_n^2)$ \\[10pt]
Periodic forcing of $x'' + \omega_0^2 x = f(t)$ &
Solve mode-by-mode: $x_n = \dfrac{a_n}{\omega_0^2 - n^2}\cos(nt) + \dfrac{b_n}{\omega_0^2 - n^2}\sin(nt)$ \\[10pt]
Resonance condition &
If $n = \omega_0$, solution grows linearly: $x_p \propto t\sin(\omega_0 t)$ \\
\bottomrule
\end{tabular}
\end{table}
