Fourier Series & Finding the Coefficients
Orthogonality • The Euler–Fourier formulas • Half-range sine and cosine expansions
1. Why This Section Exists
Separation of variables always ends in the same place. You build a family of solutions, superpose them, set $t = 0$, and are left staring at
$$\sum_{n=1}^{\infty} C_n \sin\!\left(\frac{n\pi x}{L}\right) = f(x)$$where $f$ is whatever initial temperature or displacement you were given. Two questions have to be answered before that line means anything.
Can an arbitrary $f$ really be written as a sum of sines? For a very large class of functions, yes — and this section says exactly which.
How do we find the numbers $C_n$? By a trick so useful it is worth learning on its own: orthogonality.
Everything here is applied in Section 6.3 (heat equation) and Section 6.5 (wave equation). The boundary conditions decide which kind of series you need: homogeneous Dirichlet conditions call for a sine series, homogeneous Neumann conditions call for a cosine series. That is the whole connection, and it is made precise in Section 4 below.
2. The Fourier Series of a Function
For a function $f$ defined on $-L \le x \le L$, its Fourier series is
$$f(x) \;\sim\; \frac{a_0}{2} + \sum_{n=1}^{\infty}\left[a_n \cos\!\left(\frac{n\pi x}{L}\right) + b_n \sin\!\left(\frac{n\pi x}{L}\right)\right]$$The constant term is written $a_0/2$ rather than $a_0$ so that one single formula covers every $a_n$, including $n = 0$. It is bookkeeping, nothing more.
The functions $1, \cos(\pi x/L), \sin(\pi x/L), \cos(2\pi x/L), \sin(2\pi x/L), \dots$ all have period $2L$, so the series represents a $2L$-periodic function. Outside $[-L, L]$ it simply repeats what it did inside.
3. Orthogonality: the Engine
Everything rests on the following integrals. They say that distinct members of this family of sines and cosines are orthogonal: multiply two different ones together, integrate over a full period, and the answer is zero.
To pull one coefficient out of an infinite sum, multiply the whole equation by the matching function and integrate. Every term dies except the one you aimed at. It is the same move as taking a dot product with a basis vector to extract one component — and that is exactly what it is.
Deriving the Coefficient Formulas
Start from the series and multiply both sides by $\cos(m\pi x/L)$, then integrate from $-L$ to $L$:
$$\int_{-L}^{L} f(x)\cos\!\left(\frac{m\pi x}{L}\right)dx = \frac{a_0}{2}\underbrace{\int_{-L}^{L}\cos\!\left(\frac{m\pi x}{L}\right)dx}_{=\,0} + \sum_{n=1}^{\infty} a_n \underbrace{\int_{-L}^{L}\cos\cos}_{=\,L \text{ only if } n = m} + \sum_{n=1}^{\infty} b_n \underbrace{\int_{-L}^{L}\sin\cos}_{=\,0}$$The entire infinite sum collapses to the single surviving term $a_m L$. Dividing by $L$ gives the formula. Repeating the argument with $\sin(m\pi x/L)$ gives the other one.
With the $a_0/2$ convention, the $n = 0$ case of the first formula gives $a_0 = \frac{1}{L}\int_{-L}^{L} f\,dx$, so the constant term $a_0/2$ is the average value of $f$ over the interval.
The factor is $\dfrac{1}{L}$ for the full series on $[-L, L]$, but $\dfrac{2}{L}$ for the half-range series on $[0, L]$ in Section 4. Mixing them up is the single most common error in this topic.
And the constant term of the series is $a_0/2$, not $a_0$. If you quote $a_0$ as the constant, every answer is out by a factor of two.
4. Even, Odd, and Half-Range Expansions
Symmetry does half the work for you, and it is worth checking before computing a single integral.
| If $f$ is | then | because | Example |
|---|---|---|---|
| Even, $f(-x) = f(x)$ | all $b_n = 0$: a cosine series | $f(x)\sin(\cdot)$ is odd, and an odd function integrates to zero over $[-L,L]$ | $x^2$, $\cos x$, $|x|$ |
| Odd, $f(-x) = -f(x)$ | all $a_n = 0$: a sine series | $f(x)\cos(\cdot)$ is odd | $x$, $x^3$, $\sin x$ |
| Neither | both families appear | — | $e^x$, $x + x^2$ |
Half-Range Expansions
In a PDE problem $f$ is given only on $[0, L]$ — the physical rod or string. Nothing is defined to the left of the origin, so we choose what happens there, and the choice decides which series we get.
Given $f$ on $[0, L]$:
Odd extension → a pure sine series, with
$$\boxed{\;b_n = \frac{2}{L}\int_0^L f(x)\sin\!\left(\frac{n\pi x}{L}\right)dx\;}$$Even extension → a pure cosine series, with
$$\boxed{\;a_n = \frac{2}{L}\int_0^L f(x)\cos\!\left(\frac{n\pi x}{L}\right)dx\;}$$Both use $\dfrac{2}{L}$ and integrate only over $[0, L]$: the extension is never actually computed, it is just the reason the formula looks like this.
The heat equation with $u(0,t) = u(L,t) = 0$ produces eigenfunctions $\sin(m\pi x/L)$, and its coefficients $C_m = \frac{2}{L}\int_0^L f(x)\sin(m\pi x/L)\,dx$ are exactly the half-range sine coefficients above, with $m$ written in place of $n$. You have been using this section's result already.
A sine series vanishes at $x = 0$ and $x = L$ no matter what the coefficients are — so it can only ever represent a Dirichlet problem. A cosine series has zero derivative at both ends, which is precisely the Neumann condition. The eigenfunctions of the boundary value problem are the right basis, and the BCs pick them.
5. Does the Series Actually Converge?
If $f$ is piecewise continuous on $[-L, L]$ and $f'$ is piecewise continuous there, then the Fourier series of $f$ converges at every point $x$ to
$$\frac{f(x^-) + f(x^+)}{2}$$the average of the left and right limits. At a point where $f$ is continuous this is just $f(x)$; at a jump it is the midpoint of the jump.
Take $f(x) = 1$ on $[0, L]$ and expand it in a half-range sine series. Every term vanishes at $x = 0$, so the series converges to $0$ there, not to $1$.
That is not a mistake — it is the theorem doing its job. The odd extension of $f$ jumps from $-1$ to $+1$ at the origin, and the series returns the midpoint, $0$. In a heat problem this is exactly right: the end of the rod is being held at zero.
Near a jump, every partial sum overshoots by about $9\%$ of the jump height, and adding more terms does not reduce the overshoot — it only squeezes it closer to the jump. If your plotted partial sum has little horns beside a discontinuity, nothing has gone wrong.
6. The Procedure
- Identify the interval and the kind of series. Full series on $[-L, L]$, or half-range on $[0, L]$? For a PDE, the boundary conditions decide: Dirichlet → sine, Neumann → cosine.
- Check symmetry first. On a full interval, an odd $f$ kills every $a_n$ and an even $f$ kills every $b_n$. This can halve the work before you integrate anything.
- Is $f$ already a finite sine or cosine sum? Then read the coefficients off by matching. No integration at all — the comparison shortcut from Section 6.3.
- Otherwise integrate, using $\frac{1}{L}\int_{-L}^{L}$ for a full series and $\frac{2}{L}\int_0^L$ for a half-range one. Integration by parts is almost always the tool.
- Simplify with $\cos(n\pi) = (-1)^n$ and $\sin(n\pi) = 0$. Nearly every answer in this topic ends up written in terms of $(-1)^n$.
- Split into odd and even $n$ if the result demands it, e.g. $1 - (-1)^n$ is $2$ for odd $n$ and $0$ for even $n$.
Worked Examples
Step 1 — use symmetry. $f(x) = x$ is odd, so every $a_n = 0$ immediately, including $a_0$. Only sines survive.
Step 2 — set up $b_n$.
$$b_n = \frac{1}{L}\int_{-L}^{L} x\sin\!\left(\frac{n\pi x}{L}\right)dx = \frac{2}{L}\int_{0}^{L} x\sin\!\left(\frac{n\pi x}{L}\right)dx$$(the integrand is even, so we may double the half-interval integral).
Step 3 — integrate by parts with $u = x$, $dv = \sin(n\pi x/L)\,dx$:
$$\int_0^L x\sin\!\left(\frac{n\pi x}{L}\right)dx = \left[-\frac{Lx}{n\pi}\cos\!\left(\frac{n\pi x}{L}\right)\right]_0^L + \frac{L}{n\pi}\int_0^L \cos\!\left(\frac{n\pi x}{L}\right)dx$$Step 4 — evaluate. The last integral is zero (a full number of half-periods), and the bracket gives $-\dfrac{L^2}{n\pi}\cos(n\pi)$. Using $\cos(n\pi) = (-1)^n$:
$$b_n = \frac{2}{L}\cdot\left(-\frac{L^2(-1)^n}{n\pi}\right) = \frac{2L(-1)^{n+1}}{n\pi}$$ $$\boxed{\;x \;\sim\; \frac{2L}{\pi}\sum_{n=1}^{\infty}\frac{(-1)^{n+1}}{n}\sin\!\left(\frac{n\pi x}{L}\right)\;}$$Step 5 — check the first two. $b_1 = 2L/\pi$ and $b_2 = -L/\pi$: alternating signs and decaying like $1/n$, which is the signature of a function whose periodic extension has a jump (here at $x = \pm L$).
Let $f(x) = -1$ for $-\pi < x < 0$ and $f(x) = +1$ for $0 < x < \pi$. Here $L = \pi$.
Step 1 — symmetry. $f$ is odd, so all $a_n = 0$.
Step 2 — compute $b_n$, doubling the right half as before:
$$b_n = \frac{2}{\pi}\int_0^{\pi}\sin(nx)\,dx = \frac{2}{\pi}\left[-\frac{\cos(nx)}{n}\right]_0^{\pi} = \frac{2}{n\pi}\left(1 - \cos n\pi\right) = \frac{2\left(1 - (-1)^n\right)}{n\pi}$$Step 3 — split odd and even. For even $n$, $1 - (-1)^n = 0$. For odd $n$ it equals $2$:
$$b_n = \begin{cases} \dfrac{4}{n\pi} & n \text{ odd} \\[4pt] 0 & n \text{ even}\end{cases}$$ $$\boxed{\;f(x) \;\sim\; \frac{4}{\pi}\left[\sin x + \frac{\sin 3x}{3} + \frac{\sin 5x}{5} + \cdots\right]\;}$$At the jump. At $x = 0$ every term is zero, so the series gives $0$ — the midpoint of $-1$ and $+1$, exactly as the convergence theorem promises.
This is the one you need for a rod starting at a uniform temperature with both ends held at zero.
Step 1 — use the half-range formula (note the $2/L$):
$$b_n = \frac{2}{L}\int_0^L 1 \cdot \sin\!\left(\frac{n\pi x}{L}\right)dx = \frac{2}{L}\left[-\frac{L}{n\pi}\cos\!\left(\frac{n\pi x}{L}\right)\right]_0^L$$Step 2 — evaluate.
$$= \frac{2}{n\pi}\left(1 - \cos n\pi\right) = \frac{2\left(1 - (-1)^n\right)}{n\pi} = \begin{cases} \dfrac{4}{n\pi} & n \text{ odd} \\[4pt] 0 & n \text{ even}\end{cases}$$ $$\boxed{\;1 \;\sim\; \frac{4}{\pi}\sum_{n \text{ odd}}\frac{1}{n}\sin\!\left(\frac{n\pi x}{L}\right) \quad \text{on } (0, L)\;}$$Step 3 — read the endpoints. At $x = 0$ and $x = L$ the series gives $0$, not $1$. For a rod held at zero at both ends and starting at temperature $1$, that mismatch is the physics: the ends are chilled to zero the instant the clock starts.
The cosine series is what an insulated rod (Neumann conditions) needs.
Step 1 — the constant term.
$$a_0 = \frac{2}{L}\int_0^L x\,dx = \frac{2}{L}\cdot\frac{L^2}{2} = L \qquad\Longrightarrow\qquad \frac{a_0}{2} = \frac{L}{2}$$which is the average value of $x$ on $[0,L]$, as it must be.
Step 2 — the rest, by parts.
$$a_n = \frac{2}{L}\int_0^L x\cos\!\left(\frac{n\pi x}{L}\right)dx = \frac{2}{L}\left\{\left[\frac{Lx}{n\pi}\sin\!\left(\frac{n\pi x}{L}\right)\right]_0^L - \frac{L}{n\pi}\int_0^L \sin\!\left(\frac{n\pi x}{L}\right)dx\right\}$$Step 3 — the first bracket vanishes because $\sin(n\pi) = 0$. The remaining integral gives
$$a_n = -\frac{2}{n\pi}\left[-\frac{L}{n\pi}\cos\!\left(\frac{n\pi x}{L}\right)\right]_0^L = \frac{2L\left((-1)^n - 1\right)}{n^2\pi^2}$$ $$a_n = \begin{cases} -\dfrac{4L}{n^2\pi^2} & n \text{ odd} \\[4pt] 0 & n \text{ even}\end{cases}$$ $$\boxed{\;x \;\sim\; \frac{L}{2} - \frac{4L}{\pi^2}\sum_{n \text{ odd}}\frac{1}{n^2}\cos\!\left(\frac{n\pi x}{L}\right)\;}$$This is the parabolic initial profile used in Section 6.3 (with $L = 1$, $f = x(1-x)$).
Step 1 — set up.
$$b_n = \frac{2}{L}\int_0^L \left(Lx - x^2\right)\sin\!\left(\frac{n\pi x}{L}\right)dx$$Step 2 — integrate by parts twice. The $x^2$ needs two rounds; all the boundary terms containing $\sin(n\pi)$ vanish, and the surviving pieces combine to
$$b_n = \frac{4L^2\left(1 - (-1)^n\right)}{n^3\pi^3} = \begin{cases} \dfrac{8L^2}{n^3\pi^3} & n \text{ odd} \\[4pt] 0 & n \text{ even}\end{cases}$$ $$\boxed{\;x(L-x) \;\sim\; \frac{8L^2}{\pi^3}\sum_{n \text{ odd}}\frac{1}{n^3}\sin\!\left(\frac{n\pi x}{L}\right)\;}$$Step 3 — sanity check at the midpoint. With $L = 1$ and $x = \tfrac12$ the left side is $\tfrac14$. The right side is $\frac{8}{\pi^3}\left(1 - \frac{1}{27} + \frac{1}{125} - \cdots\right) \approx 0.2500$. ✓
And the decay. $1/n^3$ — faster than both earlier examples, because this extension is continuous and has a continuous derivative. Three examples, three decay rates, each explained by how smooth the periodic extension is.
📝 Exam-Style Practice Problems
Click each problem to reveal the full solution.
Step 1 — identify. Half-range sine, $L = 2$, so the formula is $b_n = \frac{2}{2}\int_0^2 x\sin\!\left(\frac{n\pi x}{2}\right)dx = \int_0^2 x\sin\!\left(\frac{n\pi x}{2}\right)dx$.
Step 2 — by parts with $u = x$:
$$= \left[-\frac{2x}{n\pi}\cos\!\left(\frac{n\pi x}{2}\right)\right]_0^2 + \frac{2}{n\pi}\int_0^2\cos\!\left(\frac{n\pi x}{2}\right)dx$$Step 3 — evaluate. The remaining integral is zero, and the bracket gives $-\frac{4}{n\pi}\cos(n\pi)$:
$$b_n = -\frac{4(-1)^n}{n\pi} = \frac{4(-1)^{n+1}}{n\pi}$$ $$\boxed{\;x \;\sim\; \frac{4}{\pi}\sum_{n=1}^{\infty}\frac{(-1)^{n+1}}{n}\sin\!\left(\frac{n\pi x}{2}\right)\;}$$Check against the general result. Example 1 gave $b_n = 2L(-1)^{n+1}/(n\pi)$; putting $L = 2$ gives $4(-1)^{n+1}/(n\pi)$ ✓
This is the whole chapter in one problem: separation gives the shape, this section gives the numbers.
Step 1 — the general solution. From Section 6.3, with $K = 1$ and $L = 1$, Dirichlet conditions give
$$u(x,t) = \sum_{n=1}^{\infty} C_n \sin(n\pi x)\,e^{-n^2\pi^2 t}$$Step 2 — fit the initial condition. Setting $t = 0$:
$$\sum_{n=1}^{\infty} C_n\sin(n\pi x) = x(1-x)$$so the $C_n$ are the half-range sine coefficients of $x(1-x)$ — Example 5 with $L = 1$:
$$C_n = \frac{4\left(1 - (-1)^n\right)}{n^3\pi^3} = \begin{cases} \dfrac{8}{n^3\pi^3} & n \text{ odd} \\[4pt] 0 & n \text{ even}\end{cases}$$Step 3 — assemble.
$$\boxed{\;u(x,t) = \frac{8}{\pi^3}\sum_{n \text{ odd}}\frac{1}{n^3}\sin(n\pi x)\,e^{-n^2\pi^2 t}\;}$$Step 1 — recognise the form. With $L = 1$ the half-range sine basis is $\sin(n\pi x)$, and $f$ is already written in exactly that basis.
Step 2 — match. The $n = 2$ term has coefficient $5$, the $n = 7$ term has $-3$, and every other coefficient is zero.
$$\boxed{\;b_2 = 5, \quad b_7 = -3, \quad b_n = 0 \text{ otherwise}\;}$$Step 3 — why this is legitimate. Fourier coefficients are unique, so a function that is already a finite sine sum is its own Fourier series. Computing $\frac{2}{1}\int_0^1 f(x)\sin(n\pi x)dx$ would give the same answer after a page of orthogonality arguments — all of which just reproduce the matching.
Check Your Understanding
Q1: In the Fourier series $\frac{a_0}{2} + \sum\left[a_n\cos + b_n\sin\right]$ on $[-L, L]$, the coefficient $a_n$ is
Answer: (B). The full series on $[-L, L]$ carries $\frac{1}{L}$. Option (D) is the half-range cosine formula, which uses $\frac{2}{L}$ and integrates only over $[0, L]$ — correct for its own setting, wrong here. Mixing these two is the most common slip in this topic.
Q2: If $f$ is an odd function on $[-L, L]$, then
Answer: (C). For odd $f$, the product $f(x)\cos(n\pi x/L)$ is odd, and an odd function integrates to zero over a symmetric interval — so every cosine coefficient dies, $a_0$ included, leaving a pure sine series. Option (A) has it exactly backwards.
Q3: The half-range sine coefficients of $f$ on $[0, L]$ are
Answer: (B). This is precisely the $C_m$ formula used in Section 6.3 to fit the initial condition of the heat equation. Option (C) integrates over the wrong interval: $f$ is only defined on $[0,L]$, and the odd extension is the reason for the factor $2/L$, not something you integrate over.
Q4: At a jump discontinuity, the Fourier series of $f$ converges to
Answer: (C). The series cannot choose a side, so it splits the difference. For the square wave at $x = 0$ every sine term is zero, and $0$ is indeed the midpoint of $-1$ and $+1$. It does converge, so (D) is wrong — what happens near the jump is the Gibbs overshoot, which is not divergence.
Q5: Which initial condition needs no integration to find its coefficients on $[0,1]$?
Answer: (A). It is already a single term of the basis $\sin(n\pi x)$, so $b_3 = 4$ and every other coefficient is zero — read off by matching. The other three are perfectly good functions but none is a finite sine sum, so each needs the integral.
Q6: The half-range sine series of $f(x) = 1$ on $[0, L]$ converges at $x = 0$ to
Answer: (C). Every term $\sin(n\pi \cdot 0/L)$ is zero, so the sum is zero. By the convergence theorem this is the midpoint of the odd extension's jump from $-1$ to $+1$. It genuinely does not equal $f(0) = 1$ — and for a rod with its ends held at zero, that is the physically correct answer.