$\renewcommand{\Re}{\operatorname{Re}}$ $\newcommand{\erf}{\operatorname{erf}}$ $\newcommand{\dag}{\dagger}$ $\newcommand{\const}{\mathrm{const}}$
Consider system of functions \begin{equation} \Bigl\{\frac{1}{2},\qquad \cos (\frac{\pi nx}{l}), \qquad \sin (\frac{\pi nx}{l}) \quad n=1,\ldots\Bigr\} \label{equ-13.1} \end{equation} on interval $J:=[x_0,x_1]$ with $(x_1-x_0)=2l$.
These are eigenfunctions of $X''+\lambda X=0$ with periodic boundary conditions $X(x_0)=X(x_1)$, $X'(x_0)=X'(x_1)$.
Proposition 1. \begin{align*} & \int_J \cos (\frac{\pi mx}{l})\cos (\frac{\pi nx}{l})\,dx = l \delta_{mn},\\ & \int_J \sin (\frac{\pi mx}{l})\sin (\frac{\pi nx}{l})\,dx = l \delta_{mn},\\ & \int_J \cos (\frac{\pi mx}{l})\sin (\frac{\pi nx}{l})\,dx = 0, \end{align*} and \begin{align*} & \int_J \cos (\frac{\pi mx}{l})\,dx =0,\qquad & \int_J \sin (\frac{\pi mx}{l})\,dx=0,\qquad & \int_J \,dx =2l \end{align*} for all $m,n=1,2,\ldots$.
Proof. Easy; use formulae \begin{gather*} 2\cos (\alpha)\cos(\beta)=\cos(\alpha-\beta)+\cos(\alpha+\beta),\\ 2\sin (\alpha)\sin(\beta)=\cos(\alpha-\beta)-\cos(\alpha+\beta),\\ 2\sin (\alpha)\cos(\beta)=\sin(\alpha-\beta)+\sin(\alpha+\beta). \end{gather*}
Therefore according to the previous lecture Lecture 12 we arrive to decomposition \begin{equation} f(x)= \frac{1}{2}a_0 + \sum_{n=1}^\infty \bigl( a_n\cos (\frac{\pi nx}{l})+b_n \sin (\frac{\pi nx}{l}) \bigr) \label{equ-13.2} \end{equation} with coefficients calculated according to (12.7) \begin{align} a_n=& \frac{1}{l}\int_J f(x)\cos (\frac{\pi nx}{l})\,dx \qquad n=0,1,2,\ldots, \label{equ-13.3}\\ b_n= & \frac{1}{l}\int_J f(x)\sin (\frac{\pi nx}{l})\,dx \qquad n=1,2,\ldots, \label{equ-13.4} \end{align} and satisfying Parseval's equality \begin{equation} \frac{l}{2}|a_0|^2 +\sum_{n=1}^\infty l\bigl( |a_n|^2+|b_n |^2 \bigr) =\int_J |f(x)|^2\,dx. \label{equ-13.5} \end{equation}
So far this is an optional result: provided we can decompose function $f(x)$.
Now our goal is to prove that any function $f(x)$ on $J$ could be decomposed into Fourier series (\ref{equ-13.2}). First we need
Lemma 1. Let $f(x)$ be a piecewise-continuous function on $J$. Then \begin{equation} \int_J f(x)\cos(\omega x)\,dx\to 0\qquad \text{as } \omega \to \infty \label{equ-13.6} \end{equation} and the same is true for $\cos(\omega x)$ replaced by $\sin(\omega x)$.
Proof. (a) Assume first that $f(x)$ is continuously differentiable on $J$. Then integrating by parts \begin{equation*} \int_J f(x)\cos(\omega x)\,dx= \omega^{-1}f(x)\sin(\omega x)\bigr|_{x_0}^{x_1} - \omega^{-1}\int_J f(x)\sin(\omega x)\,dx=O(\omega^{-1}). \end{equation*}
(b) Assume now only that $f(x)$ is continuous on $J$. Then it could be uniformly approximated by continuous functions (proof is not difficult but we skip it anyway): \begin{equation*} \forall \varepsilon>0 \exists f_\varepsilon \in C^1(J): \forall x\in J |f(x)-f_\varepsilon (x)|\le \varepsilon. \end{equation*} Then obviously the difference between integrals (\ref{equ-13.6}) for $f$ and for $f_\varepsilon$ does not exceed $2l\varepsilon$; so choosing $\varepsilon =\varepsilon(\delta)= \delta/(4l)$ we make it $<\delta/2$. After $\varepsilon $ is chosen and $f_\varepsilon$ fixed we can choose $\omega_\varepsilon$ s.t. for $\omega>\omega_\varepsilon$ integral (\ref{equ-13.6}) for $f_\varepsilon$ does not exceed $\delta/2$ in virtue of (a). Then integral (\ref{equ-13.6}) for $f$ does not exceed $\delta$.
(c) Integral (\ref{equ-13.6}) for interval $J$ equals to the sum of integrals over intervals where $f$ is continuous. $\square$
Now calculate coefficients according to (\ref{equ-13.3})-(\ref{equ-13.4}) (albeit plug $y$ instead of $x$) and plug into partial sum: \begin{multline} S_N (x):=\frac{1}{2}a_0 + \sum_{n=1}^N \bigl( a_n\cos (\frac{\pi nx}{l})+b_n \sin (\frac{\pi nx}{l}) \bigr)=\\ \frac{1}{l}\int_J K_N(x,y)f(y)\,dy\qquad \label{equ-13.7} \end{multline} with \begin{multline} K_N(x,y)=\frac{1}{2}+ \\ \sum_{n=1}^N \bigl( \cos (\frac{\pi ny}{l}) \cos (\frac{\pi nx}{l})+ \sin (\frac{\pi ny}{l}) \sin (\frac{\pi nx}{l}) \bigr)\\= \frac{1}{2} + \sum_{n=1}^N \cos (\frac{\pi n(y-x)}{l}).\qquad \label{equ-13.8} \end{multline} Note that \begin{multline*} \sum_{n=1}^N \sin (\frac{1}{2}z)\cos (z)= \sum_{n=1}^N \bigl(\sin ((n+\frac{1}{2})z)- \sin ((n-\frac{1}{2})z) =\\ \sin ((N+\frac{1}{2})z)-\sin (\frac{1}{2}z) \end{multline*} and therefore \begin{equation} K_N(x,y)=\frac{\sin (k (N+\frac{1}{2})(x-y))}{\sin(k(x-y))},\qquad k=\frac{\pi}{l}. \label{equ-13.9} \end{equation} So \begin{equation} S_N (x) = \frac{1}{l}\int_J \frac{\sin (k (N+\frac{1}{2})(x-y))}{\sin(k(x-y))}f(y)\,dy \label{equ-13.10} \end{equation} We cannot apply Lemma 1 to this integral immediately because of denominator.
Assume that $x$ is internal point of $J$. Note that denominator vanishes on $J$ only as $y=x$. Really, $\frac{\pi}{2l}(x-y)< \pi$. Also note that derivative of denominator does not vanish as $y=x$. Then $f(y)/\sin(k(x-y))$ is a piecewise continuous function of $y$ provided all three conditions below are fulfilled:
In this case we can apply Lemma 1 and we conclude that $S_N(x)\to 0$ as $N\to \infty$. So,
If $f$ satisfies (a)-(c) then $S_N(x)\to f(x)$ as $N\to \infty$.
Let us drop condition $f(x)=0$. Then we can decompose \begin{multline} S_N (x)= \frac{1}{l}\int_J \frac{\sin (k (N+\frac{1}{2})(x-y))}{\sin(k(x-y))}\bigl(f(y)-f(x)\bigr)\,dy+\\ \frac{1}{l} \int_J \frac{\sin (k (N+\frac{1}{2})(x-y))}{\sin(k(x-y)}f(x)\,dy\qquad \label{equ-13.11} \end{multline} and the first integral tends to $0$ due to Lemma 1. We claim that the second integral is identically equal $f(x)$. Indeed, we can move $f(x)$ out of integral and consider \begin{multline} \frac{1}{l}\int_J \frac{\sin (k (N+\frac{1}{2})(x-y))}{\sin(k(x-y))},dy=\\ \frac{1}{l}\int_J \bigl(\frac{1}{2}+\sum_{n=1}^N \cos (\frac{\pi n(y-x)}{l})\bigr)\,dy \qquad\label{equ-13.12} \end{multline} where integral of the first term equals $l$ and integral of all other terms vanish.
Therefore we arrive to
Theorem 1. Let $x$ be internal point of $J$ (i.e. $x_0<x<x_1$) and let
Assume now that there is a jump at $x$. Then we need to be more subtle. First, we can replace $f(x)$ by its $2l$-periodic continuation from $J$ to $\mathbb{R}$. Then we can take any interval of the length $2l$ and result will be the same. So we take $[x-l,x+l]$. Now \begin{align*} S_N (x)= \frac{1}{l}\int_{J^-} \frac{\sin (k (N+\frac{1}{2})(x-y))}{\sin(k(x-y))} \bigl(f(y)-f(x-0)\bigr)\,dy&+\\ \frac{1}{l}\int_{J^+} \frac{\sin (k (N+\frac{1}{2})(x-y))}{\sin(k(x-y))} \bigl(f(y)-f(x+0)\bigr)\,dy&+\\ \frac{1}{l} \int_{J^-} \frac{\sin (k (N+\frac{1}{2})(x-y))}{\sin(k(x-y)}f(x-0)\,dy&+\\ \frac{1}{l} \int_{J^+} \frac{\sin (k (N+\frac{1}{2})(x-y))}{\sin(k(x-y)}f(x+0)\,dy& \end{align*} with $J^-=(x-l,l)$, $J^+=(x,x+l)$. According to <href="#lemma-13.1">Lemma 1 again the first two integrals tend to $0$ and we need to consider integrals \begin{align*} \frac{1}{l} \int_{J^-} \frac{\sin (k (N+\frac{1}{2})(x-y))}{\sin(k(x-y)}\,dy\,\\ \frac{1}{l} \int_{J^+} \frac{\sin (k (N+\frac{1}{2})(x-y))}{\sin(k(x-y)}\,dy. \end{align*} Using back transformation like in (\ref{equ-13.12}) we conclude that both these integrals are equal to $\frac{1}{2}$. Therefore we proved
Theorem 2. Let $f$ be a piecewise continuously differentiable function. Then the Fourier series converges to
The last two statements are called Stokes phenomenon.