$\renewcommand{\Re}{\operatorname{Re}}$ $\renewcommand{\Im}{\operatorname{Im}}$ $\newcommand{\erf}{\operatorname{erf}}$ $\newcommand{\dag}{\dagger}$ $\newcommand{\const}{\mathrm{const}}$ $\newcommand{\arcsinh}{\operatorname{arcsinh}}$
Consider trigonometric 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{eq-4.4.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)$.
Let us first establish this is orthogonal system.
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 Section 4.3 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{eq-4.4.2} \end{equation} with coefficients calculated according to (4.3.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{eq-4.4.3}\\ b_n= & \frac{1}{l}\int_J f(x)\sin (\frac{\pi nx}{l})\,dx \qquad n=1,2,\ldots, \label{eq-4.4.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{eq-4.4.5} \end{equation}
Exercise 1.
Prove formulae (\ref{eq-4.4.2})--(\ref{eq-4.4.5}) based on (4.3.7) and Proposition 1.
Also prove it only based on Proposition 1, that means without norms, inner products (just do all calculations from the scratch).
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{eq-4.4.2}). First we need
Definition 1.
Lemma 2. 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{eq-4.4.6} \end{equation} and the same is true for $\cos(\omega x)$ replaced by $\sin(\omega x)$.
Proof. [1] 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*}
[2] 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{eq-4.4.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{eq-4.4.6}) for $f_\varepsilon$ does not exceed $\delta/2$ in virtue of [1]. Then the absolute value of integral (\ref{eq-4.4.6}) for $f$ does not exceed $\delta$.
[3] Integral (\ref{eq-4.4.6}) for interval $J$ equals to the sum of integrals over intervals where $f$ is continuous. $\square$
Now calculate coefficients according to (\ref{eq-4.4.3})-(\ref{eq-4.4.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{eq-4.4.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{eq-4.4.8}
\end{multline}
Note that
\begin{multline*}
\sum_{n=1}^N \sin (\frac{z}{2})\cos (nz)=
\sum_{n=1}^N \Bigl(\sin \bigl((n+\frac{1}{2})z\bigr)- \sin \bigl((n-\frac{1}{2})z\bigr)\Bigr) =\
\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{eq-4.4.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{eq-4.4.10}
\end{equation}
However, we cannot apply Lemma 1 to this integral immediately because of the 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 [1]-[3] 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{eq-4.4.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{eq-4.4.12} \end{multline} where integral of the first term equals $l$ and integral of all other terms vanish.
Therefore we arrive to
Theorem 3. Let $x$ be internal point of $J$ (i.e. $x_0< x< x_1$) and let
a. $f$ be a piecewise continuously differentiable function, b. $f$ be continuous in $x$. Then the Fourier series converges to $f(x)$ at $x$.
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^-)\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^+)\bigr)\,dy\\
+&\frac{1}{l} \int_{J^-} \frac{\sin (k (N+\frac{1}{2})(x-y))}{\sin(k(x-y)}f(x^-)\,dy\\
+&\frac{1}{l} \int_{J^+}
\frac{\sin (k (N+\frac{1}{2})(x-y))}{\sin(k(x-y)}f(x^+)\,dy&
\end{align*}
with $f(x^\pm):= \lim _{y\to x^\pm} f(y)$ and $J^-=(x-l,l)$, $J^+=(x,x+l)$. According to
Theorem 4. Let $f$ be a piecewise continuously differentiable function. Then the Fourier series converges to
The last two statements are called Gibbs phenomenon. Below are partial sums of sin-Fourier decomposition of $u(x)=\left\{\begin{aligned} &1 &-&\pi<x<0,\\ -&1 &&0<x<\pi.\end{aligned}\right.$
Remark 1.
Recall from Calculus I that $f_N(x)\to f(x)$ uniformly, if \begin{gather*} \forall \varepsilon\; \exists N=N(\varepsilon)\colon f_N(x)-f(x)|<\varepsilon \; \forall x\; \forall N>N(\varepsilon). \end{gather*}