Fourier Series Solutions of Boundary Value Problems

How do you turn a single separated solution into one that matches an arbitrary initial temperature distribution? This question is left open by Separation of Variables for the Heat Equation. That article produces infinitely many building-block solutions un(x,t)=sin⁡(nπx/L)e−λntu_n(x,t)=\sin(n\pi x/L)e^{-\lambda_n t}. But no single one of them fits a generic initial condition f(x)f(x). The resolution is to superpose all of them. We choose the coefficients so the infinite sum matches f(x)f(x) at t=0t=0. This is possible precisely because the eigenfunctions sin⁡(nπx/L)\sin(n\pi x/L) are mutually orthogonal. That orthogonality turns an intractable-looking matching problem into a simple projection computation. This orthogonality trick is one of the most consequential ideas in applied mathematics. It converts a boundary value problem for a PDE into a completely explicit formula for coefficients, via an integral. The same mechanism recurs whenever a differential operator with boundary conditions produces an orthogonal family of eigenfunctions. Examples include sines, cosines, Legendre polynomials, and Bessel functions. It is the seed from which the general theory of Eigenfunction Expansions grows. The big picture is this: separation of variables reduces a PDE to two ODEs. One of these is a boundary value problem whose solutions, the eigenfunctions, form a countable orthogonal set. Any reasonable function ff on the domain can then be written as an infinite linear combination of these eigenfunctions. This is called a generalized Fourier series. The coefficients are computed by taking inner products. This works exactly as one finds vector components in Rn\mathbb{R}^n using an orthonormal basis. This article makes that computation rigorous. We state the orthogonality relations for sines and cosines on a finite interval. We prove them from scratch using only elementary calculus. We then use them to derive the coefficient formulas for Fourier sine and cosine series. We apply the results to solve concrete heat conduction problems with genuinely asymmetric initial data. This ensures no cancellation or symmetry masks an error in the method.

Key takeaways
  • Separation of variables yields eigenfunctions sin⁡(nπx/L)\sin(n\pi x/L) or cos⁡(nπx/L)\cos(n\pi x/L); a general solution is an infinite superposition of these.
  • The eigenfunctions are pairwise orthogonal on [0,L][0,L] under the integral inner product ⟨f,g⟩=∫0Lfg dx\langle f,g\rangle=\int_0^L f g\,dx.
  • Orthogonality lets you extract each coefficient cnc_n from f(x)=∑cnϕn(x)f(x)=\sum c_n \phi_n(x) by integrating fϕnf\phi_n against a normalizing constant.
  • Dirichlet conditions force a sine series; Neumann conditions force a cosine series; the boundary conditions of the PDE dictate which family appears.
  • The coefficient formulas are the same Euler–Fourier formulas used for periodic Fourier series, restricted to a half-period.
  • Key idea: orthogonality of eigenfunctions turns "match the initial data" into a single explicit integral for each coefficient.

Where this lives today

The orthogonality-and-projection technique developed here is not confined to the heat equation. In acoustics and structural engineering, the same sine and cosine eigenfunctions describe vibration modes of strings and beams, and their coefficients determine how a given pluck or impact excites each mode. In electrical engineering and signal processing, Fourier series and their discrete analogues (the DFT and FFT) decompose periodic signals into frequency components, using exactly the same orthogonality of sinusoids over a period. In quantum mechanics, the coefficient-extraction idea generalizes directly: wavefunctions are expanded in eigenfunctions of the Hamiltonian, and the "Fourier coefficients" become probability amplitudes for measuring definite energy states. In numerical analysis, truncated Fourier expansions underlie spectral methods for solving PDEs, prized for their rapid convergence on smooth periodic data. In statistics and cryptography, orthogonal function expansions and their discrete cousins appear in signal reconstruction, compressed sensing, and the algebraic structure exploited by number-theoretic transforms.

Ask the tutor: How does this coefficient-extraction method generalize when the boundary value problem produces eigenfunctions that are not sines or cosines, such as Bessel functions or Legendre polynomials?

:::definition[Fourier Sine and Cosine Series on [0,L][0,L]] Let f:[0,L]→Rf:[0,L]\to\mathbb{R} be piecewise continuous. Define the Fourier sine series of ff as

f(x)∼∑n=1∞bnsin⁡ ⁣(nπxL),bn=2L∫0Lf(x)sin⁡ ⁣(nπxL)dx,f(x) \sim \sum_{n=1}^{\infty} b_n \sin\!\left(\frac{n\pi x}{L}\right), \qquad b_n = \frac{2}{L}\int_0^L f(x)\sin\!\left(\frac{n\pi x}{L}\right)dx,

and the Fourier cosine series of ff as

f(x)∼a02+∑n=1∞ancos⁡ ⁣(nπxL),an=2L∫0Lf(x)cos⁡ ⁣(nπxL)dx,n≥0.f(x) \sim \frac{a_0}{2} + \sum_{n=1}^{\infty} a_n \cos\!\left(\frac{n\pi x}{L}\right), \qquad a_n = \frac{2}{L}\int_0^L f(x)\cos\!\left(\frac{n\pi x}{L}\right)dx, \quad n\ge 0.

These are, respectively, the ordinary Fourier series of the odd and even 2L2L-periodic extensions of ff from [0,L][0,L] to R\mathbb{R}. The symbol ∼\sim denotes formal correspondence; conditions under which the series converges pointwise to ff are addressed separately (see Convergence of Fourier Series Solutions).

Intuition

Think of piecewise continuous functions on [0,L][0,L] as vectors in an infinite-dimensional space, equipped with the inner product ⟨f,g⟩=∫0Lf(x)g(x) dx\langle f,g\rangle = \int_0^L f(x)g(x)\,dx. In ordinary Euclidean space Rn\mathbb{R}^n, if {e1,…,en}\{e_1,\dots,e_n\} is an orthogonal basis, any vector vv decomposes as v=∑cieiv=\sum c_i e_i with ci=⟨v,ei⟩/⟨ei,ei⟩c_i = \langle v,e_i\rangle/\langle e_i,e_i\rangle — you find each component by projecting onto the corresponding axis, and the other axes contribute nothing because they are perpendicular. The functions sin⁡(nπx/L)\sin(n\pi x/L) for n=1,2,3,…n=1,2,3,\dots play the role of orthogonal axes in this function space. When you "dot" ff with sin⁡(mπx/L)\sin(m\pi x/L), every term in the series except the mm-th integrates to zero, and the mm-th term integrates to a computable nonzero number. That is the entire mechanism: orthogonality annihilates cross terms and isolates one coefficient at a time. The reason sines (rather than cosines, or some other family) appear is dictated by the boundary conditions of the physical problem. A rod with both ends held at zero temperature (Dirichlet conditions u(0,t)=u(L,t)=0u(0,t)=u(L,t)=0) forces the spatial eigenfunctions to vanish at x=0,Lx=0,L, which only sin⁡(nπx/L)\sin(n\pi x/L) does among {sin⁡,cos⁡}\{\sin,\cos\}. A rod with insulated ends (Neumann conditions ux(0,t)=ux(L,t)=0u_x(0,t)=u_x(L,t)=0) forces zero slope at the ends, which selects cos⁡(nπx/L)\cos(n\pi x/L) instead (including the constant function, n=0n=0).

:::svg[Orthogonal sine eigenfunctions on [0,L][0,L] and their role as "axes"] x n=1 n=2 0 L sin(πx/L) sin(2πx/L) ∫₀ᴸ sin(πx/L)·sin(2πx/L) dx = 0 (orthogonal)

Setting up the problem

Consider the standard heat conduction boundary value problem on a rod of length LL with fixed zero end temperatures:

ut=α2uxx,0<x<L, t>0,u_t = \alpha^2 u_{xx}, \quad 0<x<L,\ t>0,
u(0,t)=0,u(L,t)=0,t>0,u(0,t)=0,\quad u(L,t)=0, \quad t>0,
u(x,0)=f(x),0<x<L.u(x,0)=f(x), \quad 0<x<L.

Separation of variables (assumed known) produces the elementary product solutions

un(x,t)=sin⁡ ⁣(nπxL)e−α2(nπ/L)2t,n=1,2,3,…,u_n(x,t) = \sin\!\left(\frac{n\pi x}{L}\right)e^{-\alpha^2 (n\pi/L)^2 t}, \qquad n=1,2,3,\dots,

each of which satisfies the PDE and both boundary conditions. Because the PDE and boundary conditions are linear and homogeneous, any finite linear combination of the unu_n is again a solution, and — accepting termwise differentiability of the infinite sum, a technical point addressed in the study of convergence — so is the infinite superposition

u(x,t)=∑n=1∞bnsin⁡ ⁣(nπxL)e−α2(nπ/L)2t.u(x,t) = \sum_{n=1}^{\infty} b_n \sin\!\left(\frac{n\pi x}{L}\right) e^{-\alpha^2(n\pi/L)^2 t}.

The only remaining requirement is the initial condition:

u(x,0)=∑n=1∞bnsin⁡ ⁣(nπxL)=f(x),0<x<L.u(x,0) = \sum_{n=1}^{\infty} b_n \sin\!\left(\frac{n\pi x}{L}\right) = f(x), \qquad 0<x<L.

This is exactly a Fourier sine series matching problem. The theorem below shows how orthogonality determines the bnb_n uniquely.

:::theorem[Orthogonality of the Sine and Cosine Eigenfunctions on [0,L][0,L]] Let L>0L>0 and let m,nm,n be positive integers. Then

∫0Lsin⁡ ⁣(mπxL)sin⁡ ⁣(nπxL)dx={0,m≠n,L2,m=n,\int_0^L \sin\!\left(\frac{m\pi x}{L}\right)\sin\!\left(\frac{n\pi x}{L}\right)dx = \begin{cases} 0, & m\neq n,\\[4pt] \dfrac{L}{2}, & m=n, \end{cases}

and for nonnegative integers m,nm,n,

∫0Lcos⁡ ⁣(mπxL)cos⁡ ⁣(nπxL)dx={0,m≠n,L,m=n=0,L2,m=n≥1.\int_0^L \cos\!\left(\frac{m\pi x}{L}\right)\cos\!\left(\frac{n\pi x}{L}\right)dx = \begin{cases} 0, & m\neq n,\\[4pt] L, & m=n=0,\\[4pt] \dfrac{L}{2}, & m=n\ge 1. \end{cases}

Moreover, for all nonnegative integers m,nm,n,

∫0Lsin⁡ ⁣(mπxL)cos⁡ ⁣(nπxL)dx\int_0^L \sin\!\left(\frac{m\pi x}{L}\right)\cos\!\left(\frac{n\pi x}{L}\right)dx

need not vanish in general (sine and cosine bases are not mutually compared here; each family is used separately, so this mixed integral plays no role in what follows).

Proof

We use the product-to-sum trigonometric identities, which follow from the angle-addition formulas

cos⁡(A−B)=cos⁡Acos⁡B+sin⁡Asin⁡B,cos⁡(A+B)=cos⁡Acos⁡B−sin⁡Asin⁡B.\cos(A-B) = \cos A\cos B + \sin A \sin B, \qquad \cos(A+B) = \cos A \cos B - \sin A \sin B.

Subtracting and adding these gives, respectively,

sin⁡Asin⁡B=12[cos⁡(A−B)−cos⁡(A+B)],cos⁡Acos⁡B=12[cos⁡(A−B)+cos⁡(A+B)].\sin A \sin B = \tfrac12\big[\cos(A-B) - \cos(A+B)\big], \qquad \cos A \cos B = \tfrac12\big[\cos(A-B) + \cos(A+B)\big].

Case m≠nm \ne n, sine-sine. Let A=mπx/LA = m\pi x/L, B=nπx/LB = n\pi x/L. Then

sin⁡ ⁣(mπxL)sin⁡ ⁣(nπxL)=12[cos⁡ ⁣((m−n)πxL)−cos⁡ ⁣((m+n)πxL)].\sin\!\left(\frac{m\pi x}{L}\right)\sin\!\left(\frac{n\pi x}{L}\right) = \frac12\left[\cos\!\left(\frac{(m-n)\pi x}{L}\right) - \cos\!\left(\frac{(m+n)\pi x}{L}\right)\right].

Since m≠nm\ne n are integers, m−nm-n and m+nm+n are nonzero integers (note m+n≥2>0m+n\ge 2 >0 always, and m−n≠0m - n \neq 0 by hypothesis). For any nonzero integer kk,

∫0Lcos⁡ ⁣(kπxL)dx=[Lkπsin⁡ ⁣(kπxL)]0L=Lkπ(sin⁡(kπ)−sin⁡0)=0,\int_0^L \cos\!\left(\frac{k\pi x}{L}\right) dx = \left[\frac{L}{k\pi}\sin\!\left(\frac{k\pi x}{L}\right)\right]_0^L = \frac{L}{k\pi}\big(\sin(k\pi) - \sin 0\big) = 0,

because sin⁡(kπ)=0\sin(k\pi)=0 for every integer kk. Applying this with k=m−nk=m-n and k=m+nk=m+n shows both terms integrate to 00, hence the whole integral is 00.

Case m=nm=n, sine-sine. Here m−n=0m-n=0, so cos⁡((m−n)πx/L)=cos⁡0=1\cos((m-n)\pi x/L) = \cos 0 = 1 identically, while m+n=2n≠0m+n = 2n \ne 0 still gives a vanishing integral as above. Thus

∫0Lsin⁡2 ⁣(nπxL)dx=12∫0L1 dx−12∫0Lcos⁡ ⁣(2nπxL)dx=L2−0=L2.\int_0^L \sin^2\!\left(\frac{n\pi x}{L}\right)dx = \frac12\int_0^L 1\,dx - \frac12\int_0^L \cos\!\left(\frac{2n\pi x}{L}\right) dx = \frac{L}{2} - 0 = \frac{L}{2}.

Case m≠nm\ne n, cosine-cosine, m,n≥0m,n\ge 0. The same identity gives

cos⁡ ⁣(mπxL)cos⁡ ⁣(nπxL)=12[cos⁡ ⁣((m−n)πxL)+cos⁡ ⁣((m+n)πxL)].\cos\!\left(\frac{m\pi x}{L}\right)\cos\!\left(\frac{n\pi x}{L}\right) = \frac12\left[\cos\!\left(\frac{(m-n)\pi x}{L}\right)+\cos\!\left(\frac{(m+n)\pi x}{L}\right)\right].

Since m≠nm \ne n, m−nm - n is a nonzero integer, so its cosine term integrates to 00 by the computation above. If m,nm,n are not both zero then m+n>0m+n>0 is a nonzero integer and that term also integrates to 00 (if m=n=0m=n=0 is excluded from this case by hypothesis m≠nm\ne n, so m+n≥1>0m+n \ge 1 > 0 automatically). Hence the whole integral is 00.

Case m=n=0m=n=0, cosine-cosine. Then cos⁡(0)cos⁡(0)=1\cos(0)\cos(0)=1, so ∫0L1 dx=L\int_0^L 1\,dx = L.

Case m=n≥1m=n\ge 1, cosine-cosine. Then m−n=0m - n = 0 gives cos⁡(0)=1\cos(0)=1 and m+n=2n≠0m+n=2n\ne 0 gives a vanishing integral, so

∫0Lcos⁡2 ⁣(nπxL)dx=12∫0L1 dx+12∫0Lcos⁡ ⁣(2nπxL)dx=L2+0=L2.\int_0^L \cos^2\!\left(\frac{n\pi x}{L}\right) dx = \frac12\int_0^L 1\, dx + \frac12\int_0^L \cos\!\left(\frac{2n\pi x}{L}\right)dx = \frac{L}{2}+0=\frac{L}{2}.

All cases are proved by direct antiderivative computation; no circularity is involved since only the angle-addition formulas and the fundamental theorem of calculus were used. ■\blacksquare

∎
CorollaryCoefficient Formulas via Orthogonality

Suppose f(x)=∑n=1∞bnsin⁡(nπx/L)f(x) = \sum_{n=1}^\infty b_n \sin(n\pi x/L) for x∈(0,L)x\in(0,L), where the series converges and may be integrated term by term after multiplying by sin⁡(mπx/L)\sin(m\pi x/L). Then for every positive integer mm,

bm=2L∫0Lf(x)sin⁡ ⁣(mπxL)dx.b_m = \frac{2}{L}\int_0^L f(x)\sin\!\left(\frac{m\pi x}{L}\right)dx.

Similarly, if f(x)=a02+∑n=1∞ancos⁡(nπx/L)f(x) = \tfrac{a_0}{2} + \sum_{n=1}^\infty a_n \cos(n\pi x/L) with term-by-term integration valid, then for every integer m≥0m \ge 0,

am=2L∫0Lf(x)cos⁡ ⁣(mπxL)dx.a_m = \frac{2}{L}\int_0^L f(x) \cos\!\left(\frac{m\pi x}{L}\right) dx.
Proof

Multiply the sine series by sin⁡(mπx/L)\sin(m\pi x/L) and integrate over [0,L][0,L], interchanging sum and integral by the stated hypothesis:

∫0Lf(x)sin⁡ ⁣(mπxL)dx=∑n=1∞bn∫0Lsin⁡ ⁣(nπxL)sin⁡ ⁣(mπxL)dx.\int_0^L f(x)\sin\!\left(\frac{m\pi x}{L}\right)dx = \sum_{n=1}^\infty b_n \int_0^L \sin\!\left(\frac{n\pi x}{L}\right)\sin\!\left(\frac{m\pi x}{L}\right)dx.

By Orthogonality of the Sine and Cosine Eigenfunctions (the theorem above), every term on the right with n≠mn\ne m vanishes, and the n=mn=m term equals bm⋅L/2b_m \cdot L/2. Hence

∫0Lf(x)sin⁡ ⁣(mπxL)dx=L2bm⟹bm=2L∫0Lf(x)sin⁡ ⁣(mπxL)dx.\int_0^L f(x)\sin\!\left(\frac{m\pi x}{L}\right)dx = \frac{L}{2} b_m \quad\Longrightarrow\quad b_m = \frac{2}{L}\int_0^L f(x)\sin\!\left(\frac{m\pi x}{L}\right)dx.

The cosine case is identical: multiply by cos⁡(mπx/L)\cos(m\pi x/L), integrate term by term, and use the cosine orthogonality relations. For m=0m=0, note ∫0Lcos⁡(0)cos⁡(0) dx=L\int_0^L \cos(0)\cos(0)\,dx = L, and the constant term in the series is written as a0/2a_0/2 precisely so that the same formula am=2L∫0Lfcos⁡(mπx/L) dxa_m = \frac2L\int_0^L f \cos(m\pi x/L)\,dx holds uniformly for m=0m=0 as well as m≥1m\ge1; this is a bookkeeping convention, verified by direct substitution m=0m=0 into the derivation above. ■\blacksquare

∎

Worked examples

Example 1 — Dirichlet rod with an asymmetric initial temperature. Solve

ut=4uxx,0<x<3, t>0,u(0,t)=u(3,t)=0,u_t = 4 u_{xx}, \quad 0<x<3,\ t>0, \qquad u(0,t)=u(3,t)=0,
u(x,0)=f(x)={x,0≤x≤1,3−x2,1<x≤3.u(x,0) = f(x) = \begin{cases} x, & 0 \le x \le 1,\\ \tfrac{3-x}{2}, & 1 < x \le 3. \end{cases}

Here α2=4\alpha^2=4, L=3L=3. Note ff is deliberately asymmetric (a triangular pulse skewed to one side, not centered at x=L/2x=L/2), and its two pieces have different slopes (11 and −12-\tfrac12), so no shortcut from symmetry is available. By separation of variables, the solution has the form

u(x,t)=∑n=1∞bnsin⁡ ⁣(nπx3)e−4(nπ/3)2t,u(x,t) = \sum_{n=1}^\infty b_n \sin\!\left(\frac{n\pi x}{3}\right) e^{-4(n\pi/3)^2 t},

and matching t=0t=0 requires f(x)=∑bnsin⁡(nπx/3)f(x) = \sum b_n \sin(n\pi x/3) on (0,3)(0,3). By the Corollary,

bn=23∫03f(x)sin⁡ ⁣(nπx3)dx=23[∫01xsin⁡ ⁣(nπx3)dx+∫133−x2sin⁡ ⁣(nπx3)dx].b_n = \frac{2}{3}\int_0^3 f(x)\sin\!\left(\frac{n\pi x}{3}\right) dx = \frac{2}{3}\left[\int_0^1 x \sin\!\left(\frac{n\pi x}{3}\right)dx + \int_1^3 \frac{3-x}{2}\sin\!\left(\frac{n\pi x}{3}\right)dx\right].

First integral. Let k=nπ/3k=n\pi/3. Using integration by parts, ∫xsin⁡(kx) dx=−xkcos⁡(kx)+1k2sin⁡(kx)\int x\sin(kx)\,dx = -\frac{x}{k}\cos(kx) + \frac{1}{k^2}\sin(kx), so

∫01xsin⁡(kx) dx=[−xkcos⁡(kx)+1k2sin⁡(kx)]01=−1kcos⁡(k)+1k2sin⁡(k).\int_0^1 x\sin(kx)\,dx = \left[-\frac{x}{k}\cos(kx)+\frac{1}{k^2}\sin(kx)\right]_0^1 = -\frac{1}{k}\cos(k) + \frac{1}{k^2}\sin(k).

With k=nπ/3k = n\pi/3:

I1=−3nπcos⁡ ⁣(nπ3)+9n2π2sin⁡ ⁣(nπ3).I_1 = -\frac{3}{n\pi}\cos\!\left(\frac{n\pi}{3}\right) + \frac{9}{n^2\pi^2}\sin\!\left(\frac{n\pi}{3}\right).

Second integral. Write 3−x2=32−x2\frac{3-x}{2} = \frac{3}{2} - \frac{x}{2}, so

I2=∫1332sin⁡(kx) dx−∫13x2sin⁡(kx) dx.I_2 = \int_1^3 \frac{3}{2}\sin(kx)\,dx - \int_1^3 \frac{x}{2}\sin(kx)\,dx.

First piece:

∫13sin⁡(kx) dx=[−1kcos⁡(kx)]13=1k(cos⁡k−cos⁡3k).\int_1^3 \sin(kx)\,dx = \left[-\frac1k \cos(kx)\right]_1^3 = \frac1k\big(\cos k - \cos 3k\big).

With k=nπ/3k=n\pi/3, 3k=nπ3k = n\pi, so cos⁡(3k)=cos⁡(nπ)=(−1)n\cos(3k)=\cos(n\pi) = (-1)^n. Thus this piece contributes

32⋅1k(cos⁡ ⁣(nπ3)−(−1)n)=92nπ(cos⁡ ⁣(nπ3)−(−1)n).\frac32 \cdot \frac{1}{k}\left(\cos\!\left(\frac{n\pi}{3}\right) - (-1)^n\right) = \frac{9}{2n\pi}\left(\cos\!\left(\frac{n\pi}{3}\right)-(-1)^n\right).

Second piece, using the antiderivative from above:

∫13xsin⁡(kx) dx=[−xkcos⁡(kx)+1k2sin⁡(kx)]13=(−3kcos⁡(3k)+1k2sin⁡(3k))−(−1kcos⁡k+1k2sin⁡k).\int_1^3 x\sin(kx)\,dx = \left[-\frac{x}{k}\cos(kx)+\frac1{k^2}\sin(kx)\right]_1^3 = \left(-\frac{3}{k}\cos(3k) + \frac1{k^2}\sin(3k)\right) - \left(-\frac1k\cos k + \frac1{k^2}\sin k\right).

Since 3k=nπ3k=n\pi, sin⁡(3k)=0\sin(3k)=0 and cos⁡(3k)=(−1)n\cos(3k)=(-1)^n, so this equals

−3k(−1)n+1kcos⁡ ⁣(nπ3)−1k2sin⁡ ⁣(nπ3)=1k(cos⁡ ⁣(nπ3)−3(−1)n)−1k2sin⁡ ⁣(nπ3).-\frac{3}{k}(-1)^n + \frac1k \cos\!\left(\frac{n\pi}{3}\right) - \frac{1}{k^2}\sin\!\left(\frac{n\pi}{3}\right) = \frac{1}{k}\left(\cos\!\left(\frac{n\pi}{3}\right) - 3(-1)^n\right) - \frac{1}{k^2}\sin\!\left(\frac{n\pi}{3}\right).

Dividing by 22 (from the −x/2-x/2 coefficient) and recalling k=nπ/3k=n\pi/3 gives, after substitution,

∫13x2sin⁡(kx) dx=32nπ(cos⁡ ⁣(nπ3)−3(−1)n)−94n2π2sin⁡ ⁣(nπ3).\int_1^3 \frac{x}{2}\sin(kx)\,dx = \frac{3}{2n\pi}\left(\cos\!\left(\frac{n\pi}{3}\right) - 3(-1)^n\right) - \frac{9}{4n^2\pi^2}\sin\!\left(\frac{n\pi}{3}\right).

Combining, I2I_2 equals the first piece minus this:

I2=92nπ(cos⁡ ⁣(nπ3)−(−1)n)−32nπ(cos⁡ ⁣(nπ3)−3(−1)n)+94n2π2sin⁡ ⁣(nπ3).I_2 = \frac{9}{2n\pi}\left(\cos\!\left(\frac{n\pi}{3}\right)-(-1)^n\right) - \frac{3}{2n\pi}\left(\cos\!\left(\frac{n\pi}{3}\right)-3(-1)^n\right) + \frac{9}{4n^2\pi^2}\sin\!\left(\frac{n\pi}{3}\right).

Simplifying the cos⁡(nπ/3)\cos(n\pi/3) and (−1)n(-1)^n coefficients:

cos⁡ ⁣(nπ3)-coefficient: 92nπ−32nπ=3nπ,(−1)n-coefficient: −92nπ+92nπ=0.\cos\!\left(\frac{n\pi}{3}\right)\text{-coefficient: } \frac{9}{2n\pi} - \frac{3}{2n\pi} = \frac{3}{n\pi}, \qquad (-1)^n\text{-coefficient: } -\frac{9}{2n\pi} + \frac{9}{2n\pi} = 0.

So remarkably the (−1)n(-1)^n terms cancel and

I2=3nπcos⁡ ⁣(nπ3)+94n2π2sin⁡ ⁣(nπ3).I_2 = \frac{3}{n\pi}\cos\!\left(\frac{n\pi}{3}\right) + \frac{9}{4n^2\pi^2}\sin\!\left(\frac{n\pi}{3}\right).

Total. Adding I1+I2I_1 + I_2:

I1+I2=(−3nπ+3nπ)cos⁡ ⁣(nπ3)+(9n2π2+94n2π2)sin⁡ ⁣(nπ3)=454n2π2sin⁡ ⁣(nπ3).I_1+I_2 = \left(-\frac{3}{n\pi}+\frac{3}{n\pi}\right)\cos\!\left(\frac{n\pi}{3}\right) + \left(\frac{9}{n^2\pi^2}+\frac{9}{4n^2\pi^2}\right)\sin\!\left(\frac{n\pi}{3}\right) = \frac{45}{4n^2\pi^2}\sin\!\left(\frac{n\pi}{3}\right).

Finally,

bn=23(I1+I2)=23⋅454n2π2sin⁡ ⁣(nπ3)=152n2π2sin⁡ ⁣(nπ3).b_n = \frac23\left(I_1+I_2\right) = \frac{2}{3}\cdot \frac{45}{4n^2\pi^2}\sin\!\left(\frac{n\pi}{3}\right) = \frac{15}{2n^2\pi^2}\sin\!\left(\frac{n\pi}{3}\right).

As a sanity check, take n=3n=3: sin⁡(π)=0\sin(\pi)=0, so b3=0b_3=0; take n=1n=1: sin⁡(π/3)=32\sin(\pi/3)=\tfrac{\sqrt3}{2}, so b1=1534π2≈25.9839.48≈0.658b_1 = \frac{15\sqrt3}{4\pi^2}\approx \frac{25.98}{39.48}\approx 0.658, a sensible magnitude comparable to the peak value f(1)=1f(1)=1. The full solution is

u(x,t)=∑n=1∞152n2π2sin⁡ ⁣(nπ3)sin⁡ ⁣(nπx3)e−4n2π2t/9.u(x,t) = \sum_{n=1}^\infty \frac{15}{2n^2\pi^2}\sin\!\left(\frac{n\pi}{3}\right)\sin\!\left(\frac{n\pi x}{3}\right) e^{-4n^2\pi^2 t/9}.

Example 2 — Neumann (insulated) rod with an asymmetric initial temperature. Solve

ut=uxx,0<x<2, t>0,ux(0,t)=ux(2,t)=0,u_t = u_{xx}, \quad 0<x<2,\ t>0, \qquad u_x(0,t) = u_x(2,t) = 0,
u(x,0)=f(x)=x2,0≤x≤2.u(x,0) = f(x) = x^2, \quad 0\le x \le 2.

Insulated ends (α2=1\alpha^2=1, L=2L=2) force the spatial eigenfunctions to satisfy X′(0)=X′(2)=0X'(0)=X'(2)=0, which selects cos⁡(nπx/2)\cos(n\pi x/2), n=0,1,2,…n=0,1,2,\dots, so the solution has the form

u(x,t)=a02+∑n=1∞ancos⁡ ⁣(nπx2)e−(nπ/2)2t.u(x,t) = \frac{a_0}{2} + \sum_{n=1}^\infty a_n \cos\!\left(\frac{n\pi x}{2}\right) e^{-(n\pi/2)^2 t}.

Matching t=0t=0 requires f(x)=x2=a02+∑n≥1ancos⁡(nπx/2)f(x) = x^2 = \frac{a_0}{2}+\sum_{n\ge1} a_n\cos(n\pi x/2) on (0,2)(0,2), an asymmetric (non-even-about-midpoint, genuinely quadratic) target function. Computing a0a_0.

a0=22∫02x2 dx=[x33]02=83.a_0 = \frac{2}{2}\int_0^2 x^2\,dx = \left[\frac{x^3}{3}\right]_0^2 = \frac{8}{3}.

So the constant term is a0/2=4/3a_0/2 = 4/3, the average value of x2x^2 over [0,2][0,2] — a useful sanity check since 12∫02x2 dx=12⋅83=43\frac{1}{2}\int_0^2 x^2\,dx = \frac{1}{2}\cdot \frac83 = \frac43. Computing ana_n for n≥1n\ge 1. With k=nπ/2k=n\pi/2,

an=∫02x2cos⁡(kx) dx.a_n = \int_0^2 x^2 \cos(kx)\,dx.

Integrate by parts twice. First, ∫x2cos⁡(kx) dx=x2ksin⁡(kx)+2xk2cos⁡(kx)−2k3sin⁡(kx)\int x^2\cos(kx)\,dx = \frac{x^2}{k}\sin(kx) + \frac{2x}{k^2}\cos(kx) - \frac{2}{k^3}\sin(kx) (differentiate to check: ddx\frac{d}{dx} of this expression is

2xksin⁡(kx)+x2cos⁡(kx)+2k2cos⁡(kx)−2xksin⁡(kx)−2k2cos⁡(kx)=x2cos⁡(kx),\frac{2x}{k}\sin(kx) + x^2\cos(kx) + \frac{2}{k^2}\cos(kx) - \frac{2x}{k}\sin(kx) - \frac{2}{k^2}\cos(kx) = x^2\cos(kx),

confirming the antiderivative is correct). Evaluate from 00 to 22, noting 2k=nπ2k = n\pi so sin⁡(2k)=sin⁡(nπ)=0\sin(2k) = \sin(n\pi)=0 and cos⁡(2k)=cos⁡(nπ)=(−1)n\cos(2k)=\cos(n\pi)=(-1)^n:

an=[x2ksin⁡(kx)+2xk2cos⁡(kx)−2k3sin⁡(kx)]02=4k⋅0+4k2(−1)n−2k3⋅0−0=4(−1)nk2.a_n = \left[\frac{x^2}{k}\sin(kx)+\frac{2x}{k^2}\cos(kx)-\frac{2}{k^3}\sin(kx)\right]_0^2 = \frac{4}{k}\cdot 0 + \frac{4}{k^2}(-1)^n - \frac{2}{k^3}\cdot 0 - 0 = \frac{4(-1)^n}{k^2}.

Substituting k=nπ/2k=n\pi/2, so k2=n2π2/4k^2 = n^2\pi^2/4:

an=4(−1)nn2π2/4=16(−1)nn2π2.a_n = \frac{4(-1)^n}{n^2\pi^2/4} = \frac{16(-1)^n}{n^2\pi^2}.

As a check, n=1n=1 gives a1=−16/π2≈−1.621a_1 = -16/\pi^2 \approx -1.621, a plausible-sized correction to the mean value 4/3≈1.3334/3\approx 1.333; n=2n=2 gives a2=16/(4π2)=4/π2≈0.405a_2 = 16/(4\pi^2)=4/\pi^2\approx 0.405. The full solution is

u(x,t)=43+∑n=1∞16(−1)nn2π2cos⁡ ⁣(nπx2)e−n2π2t/4.u(x,t) = \frac{4}{3} + \sum_{n=1}^\infty \frac{16(-1)^n}{n^2\pi^2}\cos\!\left(\frac{n\pi x}{2}\right) e^{-n^2\pi^2 t/4}.

Note that as t→∞t\to\infty, u(x,t)→4/3u(x,t)\to 4/3, the spatial average of the initial data — exactly as expected physically for an insulated rod with no heat loss, where total thermal energy is conserved and temperature equilibrates to the mean.

CounterexampleDropping orthogonality: mismatched boundary conditions break the coefficient formula

The coefficient formulas in the Corollary rely entirely on the orthogonality relations of the Theorem, which in turn depend on using eigenfunctions that actually satisfy the stated boundary conditions. Suppose one mistakenly tries to expand a function on [0,L][0,L] using the family ϕn(x)=sin⁡ ⁣(nπxL+π4)\phi_n(x) = \sin\!\left(\frac{n\pi x}{L} + \frac{\pi}{4}\right) — sines shifted by a fixed nonzero phase, which do not vanish at x=0x=0 and hence are not eigenfunctions of the Dirichlet problem at all. These functions are not orthogonal on [0,L][0,L] in general. For instance, with L=πL=\pi, direct computation using the product-to-sum identity gives

∫0πsin⁡ ⁣(x+π4)sin⁡ ⁣(2x+π4)dx=12∫0π[cos⁡ ⁣(x−π4)⋅(−1)−cos⁡ ⁣(3x+π2)]dx,\int_0^\pi \sin\!\left(x+\frac{\pi}{4}\right)\sin\!\left(2x+\frac{\pi}{4}\right)dx = \frac12\int_0^\pi \left[\cos\!\left(x-\frac{\pi}{4}\right) \cdot(-1)- \cos\!\left(3x+\frac{\pi}{2}\right)\right]dx,

which, upon evaluating (using cos⁡(A−B)−cos⁡(A+B)\cos(A-B)-\cos(A+B) with A=x+π/4,B=2x+π/4A=x+\pi/4, B=2x+\pi/4, so A−B=−xA - B = -x, A+B=3x+π/2A+B = 3x+\pi/2), reduces to

12∫0πcos⁡(−x) dx−12∫0πcos⁡ ⁣(3x+π2)dx=12[sin⁡x]0π⋅(−1)∣sign from cos⁡(−x)=cos⁡x−12[sin⁡(3x+π/2)3]0π.\frac12\int_0^\pi \cos(-x)\,dx - \frac12\int_0^\pi \cos\!\left(3x+\frac{\pi}{2}\right)dx = \frac12\big[\sin x\big]_0^\pi \cdot(-1)\Big|_{\text{sign from }\cos(-x)=\cos x} - \frac12\left[\frac{\sin(3x+\pi/2)}{3}\right]_0^\pi.

Concretely: ∫0πcos⁡(x) dx=[sin⁡x]0π=0\int_0^\pi \cos(x)\,dx = [\sin x]_0^\pi = 0, but ∫0πcos⁡(3x+π/2) dx=13[sin⁡(3x+π/2)]0π=13(sin⁡(3π+π/2)−sin⁡(π/2))=13(−1−1)=−23\int_0^\pi \cos(3x+\pi/2)\,dx = \frac13\left[\sin(3x+\pi/2)\right]_0^\pi = \frac13\left(\sin(3\pi+\pi/2)-\sin(\pi/2)\right) = \frac13\left(-1-1\right) = -\frac23. So the integral equals 12(0)−12(−23)=13≠0\frac12(0) - \frac12\left(-\frac23\right) = \frac13 \ne 0. Since ϕ1\phi_1 and ϕ2\phi_2 are not orthogonal, attempting to write f=∑cnϕnf=\sum c_n\phi_n and extract c1c_1 via c1=2π∫0πf ϕ1 dxc_1 = \frac{2}{\pi}\int_0^\pi f\,\phi_1\,dx produces contamination from every other coefficient cnc_n (n≠1n\ne1), because the cross terms ∫ϕnϕ1 dx\int \phi_n\phi_1\,dx do not vanish. The resulting "coefficients" do not reproduce ff when resummed, and worse, ϕn(0)=sin⁡(π/4)=22≠0\phi_n(0)=\sin(\pi/4)=\frac{\sqrt2}{2}\ne 0, so these functions do not even satisfy the Dirichlet boundary condition the physical problem demands. This shows both why the eigenfunctions must be chosen to match the actual boundary conditions, and why orthogonality — not just "some infinite family of oscillating functions" — is the load-bearing hypothesis behind the coefficient formula.

Scope, edge cases & common traps

SituationCorrect choiceCommon trap
u(0,t)=u(L,t)=0u(0,t)=u(L,t)=0 (Dirichlet)Fourier sine series, sin⁡(nπx/L)\sin(n\pi x/L)Using a cosine series, which cannot vanish at both ends unless f≡f\equiv const
ux(0,t)=ux(L,t)=0u_x(0,t)=u_x(L,t)=0 (Neumann)Fourier cosine series, including n=0n=0 termForgetting the constant term a0/2a_0/2, which encodes the average value
Mixed conditions (e.g. u(0,t)=0, ux(L,t)=0u(0,t)=0,\ u_x(L,t)=0)Neither pure sine nor pure cosine; eigenfunctions are sin⁡((2n−1)πx/2L)\sin\big((2n-1)\pi x/2L\big)Applying the plain sine/cosine coefficient formulas verbatim
ff discontinuousSeries still converges pointwise to the average of left/right limits at jumps (see Convergence of Fourier Series Solutions)Assuming the series equals ff exactly at every point
Term-by-term integration to derive coefficientsValid once uniform convergence (or at least justified interchange) is establishedTreating the derivation as fully rigorous without addressing convergence of the assumed expansion

The mathematician behind it

Origins · 1 minJean-Baptiste Joseph Fourier and how this was discovered
JJ
Jean-Baptiste Joseph Fourier
1768–1830 · Napoleonic-era France, École Polytechnique and the Prefecture of Isère

Fourier developed his trigonometric series while studying the analytic theory of heat conduction, presenting the core ideas to the Institut de France in 1807. His claim — that an arbitrary function could be represented as an infinite sum of sines and cosines — was met with skepticism by contemporaries including Lagrange and Laplace, since it seemed to contradict the intuition that a sum of smooth periodic functions should itself be smooth and periodic in a simple sense. Fourier's physical motivation was concrete: modeling how heat diffuses through a solid body given an arbitrary initial temperature distribution, exactly the boundary value problem this article treats.

History
- 1807: Fourier submits his memoir on heat propagation to the Institut de France, introducing trigonometric series expansions.
- 1822: Fourier publishes Théorie analytique de la chaleur, the definitive treatment of the heat equation and its series solutions.
- 1829: Dirichlet gives the first rigorous sufficient conditions for pointwise convergence of Fourier series.
- 1837: Sturm and Liouville generalize the orthogonality mechanism to a broad class of eigenvalue problems, the ancestor of general Eigenfunction Expansions.
- 1966: Carleson proves that Fourier series of square-integrable functions converge almost everywhere, closing a century-and-a-half-old convergence question.
Why do Dirichlet boundary conditions force a sine series rather than a cosine series?

The spatial eigenfunctions X(x)X(x) from separation of variables must satisfy the same homogeneous boundary conditions as uu. For u(0,t)=u(L,t)=0u(0,t)=u(L,t)=0, this forces X(0)=X(L)=0X(0)=X(L)=0. Among the general solution X(x)=Acos⁡(nπx/L)+Bsin⁡(nπx/L)X(x)=A\cos(n\pi x/L)+B\sin(n\pi x/L) to the resulting ODE eigenvalue problem, requiring X(0)=0X(0)=0 forces A=0A=0, leaving only sine terms, and requiring X(L)=0X(L)=0 then quantizes nn to a positive integer. Cosines cannot satisfy X(0)=0X(0)=0 unless they vanish identically, so they are excluded entirely from a pure Dirichlet problem.

What if the initial data ff is discontinuous — does the Fourier series still make sense?

The coefficient formulas bn=2L∫0Lfsin⁡(nπx/L) dxb_n = \frac{2}{L}\int_0^L f\sin(n\pi x/L)\,dx only require ff to be integrable (piecewise continuous suffices), so the coefficients are always well-defined regardless of continuity. What changes is the behavior of the resulting series: at a jump discontinuity, the series converges to the average of the left- and right-hand limits, not to ff itself at that exact point. This subtlety, along with rates of convergence and the Gibbs phenomenon near jumps, is developed fully in Convergence of Fourier Series Solutions.

Can I use a cosine series even when the boundary conditions are Dirichlet, just as a different valid expansion?

No — a cosine series would not satisfy the boundary conditions of the PDE. If you set u(x,t)=∑ancos⁡(nπx/L)e−λntu(x,t) = \sum a_n \cos(n\pi x/L) e^{-\lambda_n t} and try to impose u(0,t)=0u(0,t)=0, you get ∑ane−λnt=0\sum a_n e^{-\lambda_n t}=0 for all tt, forcing every an=0a_n=0 (except in trivial cases), collapsing the solution to zero. The eigenfunctions must be chosen to satisfy the actual homogeneous boundary conditions of the specific problem; sine and cosine series are not interchangeable tools but are tied to Dirichlet and Neumann conditions respectively.

Does this method work if the boundary conditions are inhomogeneous, like u(0,t)=T1≠0u(0,t)=T_1 \ne 0?

Not directly — the superposition argument requires each term unu_n to individually satisfy homogeneous boundary conditions so that linear combinations still do. For inhomogeneous boundary data, the standard technique is to first subtract off a steady-state (time-independent) solution v(x)v(x) solving the same boundary values, reducing the problem to one with homogeneous boundary conditions for w=u−vw=u-v, which is then solved by the Fourier series method described here.

How is choosing Fourier coefficients here similar to finding components of a vector?

The analogy is exact under the right framework. Treat piecewise continuous functions on [0,L][0,L] as vectors in an inner product space with ⟨f,g⟩=∫0Lfg dx\langle f,g\rangle=\int_0^L fg\,dx. The functions sin⁡(nπx/L)\sin(n\pi x/L) play the role of an orthogonal basis, just like {e1,…,en}\{e_1,\dots,e_n\} in Rn\mathbb{R}^n. Just as v=∑i⟨v,ei⟩⟨ei,ei⟩eiv = \sum_i \frac{\langle v,e_i\rangle}{\langle e_i,e_i\rangle} e_i in finite dimensions, here f=∑n⟨f,sin⁡(nπx/L)⟩⟨sin⁡(nπx/L),sin⁡(nπx/L)⟩sin⁡(nπx/L)f = \sum_n \frac{\langle f,\sin(n\pi x/L)\rangle}{\langle \sin(n\pi x/L),\sin(n\pi x/L)\rangle}\sin(n\pi x/L), which is exactly the coefficient formula derived above, with ⟨sin⁡(nπx/L),sin⁡(nπx/L)⟩=L/2\langle\sin(n\pi x/L),\sin(n\pi x/L)\rangle=L/2.

Why does the coefficient formula involve 2/L2/L rather than 1/L1/L?

This factor comes directly from the normalization constant ∫0Lsin⁡2(nπx/L) dx=L/2\int_0^L \sin^2(n\pi x/L)\,dx = L/2 computed in the orthogonality theorem. Since bm=⟨f,sin⁡(mπx/L)⟩/⟨sin⁡(mπx/L),sin⁡(mπx/L)⟩b_m = \langle f,\sin(m\pi x/L)\rangle / \langle \sin(m\pi x/L),\sin(m\pi x/L)\rangle, and the denominator equals L/2L/2, dividing by L/2L/2 is the same as multiplying by 2/L2/L. The factor of 22 is not arbitrary — it precisely compensates for the fact that sin⁡(nπx/L)\sin(n\pi x/L) has "length-squared" L/2L/2 rather than LL over the interval.

What happens for boundary conditions that are neither pure Dirichlet nor pure Neumann, such as one fixed end and one insulated end?

The separation-of-variables eigenvalue problem changes, and the eigenfunctions are no longer plain sines or cosines of nπx/Ln\pi x/L. For X(0)=0X(0)=0 and X′(L)=0X'(L)=0, solving the ODE and applying both conditions gives eigenfunctions sin⁡((2n−1)πx/(2L))\sin\big((2n-1)\pi x/(2L)\big) for n=1,2,3,…n=1,2,3,\dots — odd multiples of a quarter-period frequency. These still form an orthogonal family on [0,L][0,L] by an analogous product-to-sum argument, and the same projection technique applies, but with different eigenvalues and a different normalization constant in the coefficient formula.

Before this

Where this leads