Flow Lab

Syllabus / Module 8: Boundary Value Problems & Fourier Series

Lesson 8.4

Even & Odd Extensions: Sine and Cosine Series

Half-range expansions, which extension matches which boundary condition, and preparing for separation of variables.

Written byClaude Sonnet

Prerequisites:8.3 Fourier Series
🌊
Why this matters for simulation: Wall boundary conditions in spectral fluid solvers are enforced by choosing sine or cosine bases.

By the end of this lesson you can…

  • Derive the sine and cosine series of a function given on $[0, \pi]$ (or $[0, L]$) by extending it oddly or evenly and applying the Euler–Fourier formulas.
  • Match a boundary condition to a series: Dirichlet ends to sines, Neumann ends to cosines, and one Dirichlet plus one Neumann end to the odd multiples of a half-wavenumber.
  • Predict the decay rate of the coefficients from the smoothness of the extension, and say which extension of a given $f$ converges faster.
  • Explain why a partial sum can converge to $f$ in the interior while its value or slope at the wall stays stuck, and what that means for a PDE.
  • Compute half-range coefficients and their rms errors numerically and check them against closed forms.
On this page
·
  1. The problem: data on half an interval
  2. The odd extension gives the sine series
  3. The even extension gives the cosine series
  4. Worked example 1: f(x)=xf(x) = xf(x)=x both ways
  5. Why the choice changes convergence: smoothness of the extension
  6. Boundary conditions pick the series
  7. Worked example 2: the constant and the parabola, step by step
  8. Computing it
  9. What comes next
  10. Concept checks
  11. Problems
  12. Key Takeaways

8.3 Fourier Series ended on a cliff-hanger. A heat or flow problem hands you f(x)f(x) only on the physical interval [0,π][0, \pi], but the Fourier series of the last lesson wants a function on a full period (−π,π)(-\pi, \pi). Whatever we invent on the missing half is a choice, and the lesson showed the choice has consequences: for f(x)=xf(x) = x the odd extension (a sawtooth) converged with a rms error of 0.2250.225 at 39 terms, while the even extension (a triangle) reached 0.001450.00145. A factor of 150 from a decision that costs nothing to make.

This lesson turns that decision into a rule. The rule has two halves, and they agree. The boundary conditions of the physical problem say which functions are allowed (8.2 Eigenvalue Problems & Sturm–Liouville Theory: Dirichlet ends give sines, Neumann ends give cosines), and the smoothness of the extension says how fast the series converges. For a simulation the first half is not optional: a solver that represents a wall velocity with the wrong basis violates the wall condition at every time step.

▶ Video Reflecting a function across the wall: the odd reflection produces a sine series, the even reflection a cosine seriescaptions only
Transcript
  1. A heat or flow problem hands you f on the physical interval from zero to pi, and nothing else. A Fourier series wants a full period, so we must invent the left half. There are two natural ways. Rotate the graph half a turn about the origin: the odd extension. Or mirror it across the vertical axis: the even extension. It is a choice, and last time it made a factor of 150 difference.
  2. The odd extension first. Cosine times an odd function is odd, so it integrates to zero: every a k vanishes. Sine times an odd function is even, so the integral over minus pi to pi is twice the integral over zero to pi. That gives the sine series: b k is 2 over pi times the integral of f sine k x. The 2 over pi is one over the squared length of sine k x on the half interval, since sine squared integrates to pi over 2.
  3. The even extension is f of the absolute value of x. Now sine times f is odd, so every b k vanishes, and the cosine series has a k equal to 2 over pi times the integral of f cosine k x. Set k to 0 and a 0 over 2 is the average of f. The constant mode is always there: it is the lambda equals 0 eigenfunction of the insulated rod, which keeps its heat.
  4. Take f equal x. The sine series has b k equal to 2 times minus 1 to the k plus 1, over k: 2, minus 1, two thirds, minus a half. The cosine series has a 0 equal pi, and a k equal minus 4 over pi k squared for odd k. These are the sawtooth and the triangle of the last lesson. The sim finds a 1, a 3 and a 5 by quadrature alone: minus 1.273240, minus 0.141471 and minus 0.050930. Notice the tails: one over k against one over k squared.
  5. Why the gap? The series is the Fourier series of the extension, so its decay is the extension's smoothness. The odd extension is continuous only if f vanishes at both walls. Otherwise it jumps, and you pay a 1 over k tail and a Gibbs overshoot. The even extension is always continuous, but has a corner unless the slope is zero at the walls, so it pays 1 over k squared. The winner depends on f: cosine for x, sine for x times pi minus x, and for the constant 1 the cosine series is exact.
  6. But smoothness only says what is cheap. The boundary conditions say what is allowed. Dirichlet ends give sines, with lambda equal k squared. Neumann ends give cosines. One Dirichlet end and one Neumann end give sine of k minus a half times x, with lambda equal k minus a half, squared. That extension is odd about 0 and even about pi, with period 4 pi. Every partial sum inherits the boundary condition of its modes.
  7. That last point has a price. Take f equal x with 7 terms. The sine sum is exactly 0 at the wall x equals pi, although f is pi there, and its slope is minus 14, which is minus 2 N and grows without bound. The cosine sum has slope exactly zero at both walls although f has slope 1, and its values creep toward the truth: 0.0792 at the left wall, 3.0624 at the right. The series converges inside, but its derivative does not converge at the wall. Read fluxes from the equation.
  8. Here are the error curves for f equal x. At 39 terms the sine series has root mean square error 0.2250, the cosine series 0.00145, and the mixed series 0.00107: its extension has one corner per period of 4 pi, instead of two per 2 pi. For x times pi minus x the roles reverse. The sine series reaches 0.00006 and the cosine series only 0.00474. The odd extension there has no jump and no corner.
  9. Fluid solvers face this choice at every time step. At a solid wall the normal velocity must vanish, so it is expanded in sines. The pressure in the projection step has zero normal gradient, so it uses cosines. Fast sine and cosine transforms, computed with the F F T, do the work. Even on a grid, the discrete sine vectors are exact eigenvectors of the second difference matrix with fixed ends.
  10. To recap. Reflect f oddly for sines, evenly for cosines. The boundary conditions choose which, and the smoothness of the extension sets the speed. Partial sums obey the wall condition, but their derivatives do not converge there. Next, we put these series to work on the heat equation by separation of variables: each mode decays at its own rate, and the 1 over k tail disappears the instant time starts.

The problem: data on half an interval

Take a rod, a channel or a string on 0≤x≤π0 \le x \le \pi (8.1 Two-Point Boundary Value Problems explains how to rescale any interval to this one). The initial profile ff lives on [0,π][0, \pi] only. We want to write f=∑ckykf = \sum c_k y_k with the yky_k eigenfunctions of −y′′=λy-y'' = \lambda y for the physical boundary conditions. By the orthogonality of the last two lessons the coefficients are projections, so the only real question is which yky_k.

A full-period Fourier series needs ff on (−π,π)(-\pi, \pi). We have it on the right half. So reflect the graph across the vertical axis in one of the two natural ways, apply the formulas of 8.3 Fourier Series, and read off the answer on (0,π)(0, \pi), where the extension equals ff.

The odd extension gives the sine series

Define fodd(x)=f(x)f_{\text{odd}}(x) = f(x) for 0<x<π0 \lt x \lt \pi and fodd(x)=−f(−x)f_{\text{odd}}(x) = -f(-x) for −π<x<0-\pi \lt x \lt 0, repeated with period 2π2\pi. The graph on the left is the right-hand graph rotated by half a turn about the origin. For foddf_{\text{odd}} the product foddcos⁡kxf_{\text{odd}}\cos kx is odd and integrates to zero over a symmetric interval, so every ak=0a_k = 0. The product foddsin⁡kxf_{\text{odd}}\sin kx is even, so the integral over (−π,π)(-\pi, \pi) is twice the integral over (0,π)(0, \pi):

f(x)=∑k=1∞bksin⁡kx,bk=2π∫0πf(x)sin⁡kx dx(0<x<π).f(x) = \sum_{k=1}^{\infty} b_k \sin kx, \qquad b_k = \frac{2}{\pi}\int_0^{\pi} f(x)\sin kx\,dx \qquad (0 \lt x \lt \pi).

The factor 2/π2/\pi is 1/∥sin⁡kx∥21/\|\sin kx\|^2 on the half interval, since ∫0πsin⁡2kx dx=π/2\int_0^\pi \sin^2 kx\,dx = \pi/2. It is the projection formula of 1.1 Vectors, Linear Combinations & Span: dot product over squared length.

The even extension gives the cosine series

Define feven(x)=f(∣x∣)f_{\text{even}}(x) = f(|x|): the graph is mirrored across the vertical axis. Now fevensin⁡kxf_{\text{even}}\sin kx is odd, so all bk=0b_k = 0, and

f(x)=a02+∑k=1∞akcos⁡kx,ak=2π∫0πf(x)cos⁡kx dx(k≥0).f(x) = \frac{a_0}{2} + \sum_{k=1}^{\infty} a_k \cos kx, \qquad a_k = \frac{2}{\pi}\int_0^{\pi} f(x)\cos kx\,dx \qquad (k \ge 0).

With k=0k = 0 the formula says a0/2=1π∫0πf dxa_0/2 = \frac1\pi\int_0^\pi f\,dx, the average of ff. The cosine series always contains the constant mode, which is the eigenfunction for λ=0\lambda = 0 of the Neumann problem (the insulated rod keeps its total heat).

On an interval [0,L][0, L] substitute x→πx/Lx \to \pi x/L: the modes are sin⁡(kπx/L)\sin(k\pi x/L) and cos⁡(kπx/L)\cos(k\pi x/L), and the prefactor 2/π2/\pi becomes 2/L2/L.

Worked example 1: f(x)=xf(x) = x both ways

For the sine series, integrate by parts, ∫xsin⁡kx dx=−xcos⁡kxk+sin⁡kxk2\int x\sin kx\,dx = -\frac{x\cos kx}{k} + \frac{\sin kx}{k^2}:

bk=2π[−xcos⁡kxk]0π=2(−1)k+1k,x=2(sin⁡x−sin⁡2x2+sin⁡3x3−⋯ ).b_k = \frac2\pi\Bigl[-\frac{x\cos kx}{k}\Bigr]_0^\pi = \frac{2(-1)^{k+1}}{k}, \qquad x = 2\Bigl(\sin x - \frac{\sin 2x}{2} + \frac{\sin 3x}{3} - \cdots\Bigr).

For the cosine series a0=2π⋅π22=πa_0 = \frac{2}{\pi}\cdot\frac{\pi^2}{2} = \pi, and for k≥1k \ge 1, using ∫xcos⁡kx dx=xsin⁡kxk+cos⁡kxk2\int x\cos kx\,dx = \frac{x\sin kx}{k} + \frac{\cos kx}{k^2},

ak=2π⋅(−1)k−1k2={−4πk2k odd0k even,x=π2−4π(cos⁡x+cos⁡3x9+cos⁡5x25+⋯ ).a_k = \frac{2}{\pi}\cdot\frac{(-1)^k - 1}{k^2} = \begin{cases} -\dfrac{4}{\pi k^2} & k\text{ odd}\\[2mm] 0 & k\text{ even}\end{cases}, \qquad x = \frac\pi2 - \frac4\pi\Bigl(\cos x + \frac{\cos 3x}{9} + \frac{\cos 5x}{25} + \cdots\Bigr).

These are exactly the sawtooth and triangle series of the last lesson, now read as two different expansions of the same function on (0,π)(0, \pi). The sim computes every coefficient by quadrature and never looks at a closed form. It returns b1,…,b5=2.000000, −1.000000, 0.666667, −0.500000, 0.400000b_1, \dots, b_5 = 2.000000,\ -1.000000,\ 0.666667,\ -0.500000,\ 0.400000 and, for the cosine series, a0=3.141593a_0 = 3.141593 and a1,a3,a5=−1.273240, −0.141471, −0.050930a_1, a_3, a_5 = -1.273240,\ -0.141471,\ -0.050930 with a2=a4=0a_2 = a_4 = 0.

◆ Interactive Choose f on [0, pi]; compare the sine, cosine and mixed series, their extensions, their end values and slopes, and their errors

Loading simulation…

What to try. (1) f=xf = x with N=3,7,15,39N = 3, 7, 15, 39: compare the three error curves. (2) Switch the middle panel between the odd, even and mixed extensions and see the sawtooth, the triangle and a third shape. (3) f=1f = 1: the cosine series is exact in one term. (4) f=x(π−x)f = x(\pi - x): now the sine series is the winner. (5) Read the table of end values and end slopes: the sine sum is stuck at 00 at both walls and the cosine sum at slope 00, whatever NN is.

Why the choice changes convergence: smoothness of the extension

The series for ff on (0,π)(0, \pi) is the Fourier series of the extension, so its coefficients decay at the rate the extension’s smoothness allows (8.3 Fourier Series: a jump gives 1/k1/k, a corner 1/k21/k^2, a jump in f′′f'' gives 1/k31/k^3). So ask what each extension does at the walls x=0x = 0 and x=πx = \pi.

Odd extension. Continuity at 00 needs f(0)=−f(0)f(0) = -f(0), so f(0)=0f(0) = 0, and by periodicity the same at π\pi: the odd extension is continuous only if f(0)=f(π)=0f(0) = f(\pi) = 0. Otherwise it jumps, by 2f(0)2f(0) at 00, and the series pays a 1/k1/k tail and a Gibbs overshoot. The slope, in contrast, is automatically continuous: reflecting through the origin gives fodd′(−x)=f′(x)f_{\text{odd}}'(-x) = f'(x). What can break is the second derivative.

Even extension. The extension is always continuous, because f(∣x∣)f(|x|) meets itself at 00. The slope is another matter: the right slope is f′(0+)f'(0^+) and the left slope is −f′(0+)-f'(0^+), so there is a corner unless f′(0)=0f'(0) = 0, and likewise at π\pi. So the cosine series never jumps but pays a 1/k21/k^2 tail for any ff with nonzero slope at a wall.

The sim confirms these rules (three of its four functions shown). Root-mean-square errors on (0,π)(0, \pi), measured directly on a 4000-point grid:

ff on [0,π][0, \pi]NNsinecosine
xx330.75340.75340.04350.0435
xx39390.22500.22500.001450.00145
11330.31520.315200 (exact)
1139390.10060.100600 (exact)
x(π−x)x(\pi - x)330.01560.01560.20290.2029
x(π−x)x(\pi - x)39390.000060.000060.004740.00474

For f=xf = x the jump at π\pi in the odd extension costs the sine series a factor of about 150 at N=39N = 39. For f=1f = 1 the even extension is just the constant, so one mode captures everything while the sine series is a square wave with bk=4/(πk)b_k = 4/(\pi k) and the familiar overshoot: its maximum is 1.20041.2004 at N=3N = 3 and still 1.17921.1792 at N=39N = 39. For f=x(π−x)f = x(\pi - x), which vanishes at both walls, the roles reverse: the odd extension is continuous with a continuous slope, only f′′f'' jumps from −2-2 to +2+2, the coefficients are bk=8/(πk3)b_k = 8/(\pi k^3) for odd kk (b1=2.546479b_1 = 2.546479, b3=0.094314b_3 = 0.094314, b5=0.020372b_5 = 0.020372), and 39 terms leave an error of 6×10−56\times 10^{-5}. The even extension has corners of slope ±π\pm\pi at x=0x = 0 and the coefficients ak=−4/k2a_k = -4/k^2 for even kk (a2=−1.000000a_2 = -1.000000, a4=−0.250000a_4 = -0.250000, a0=3.289868=π2/3a_0 = 3.289868 = \pi^2/3), giving 0.00470.0047, about 85 times worse.

Boundary conditions pick the series

The smoothness rule says what is cheap. The boundary conditions say what is allowed, and in a PDE they win. Look at the eigenfunctions of −y′′=λy-y'' = \lambda y on [0,π][0, \pi] from 8.2 Eigenvalue Problems & Sturm–Liouville Theory:

endseigenfunctionsλk\lambda_kseries
Dirichlet, y(0)=y(π)=0y(0) = y(\pi) = 0sin⁡kx\sin kx, k≥1k \ge 1k2k^2sine
Neumann, y′(0)=y′(π)=0y'(0) = y'(\pi) = 0cos⁡kx\cos kx, k≥0k \ge 0k2k^2cosine
y(0)=0y(0) = 0, y′(π)=0y'(\pi) = 0sin⁡((k−12)x)\sin\bigl((k - \tfrac12)x\bigr), k≥1k \ge 1(k−12)2(k - \tfrac12)^2mixed

Every partial sum inherits the boundary condition of its modes. Each sin⁡kx\sin kx vanishes at both walls, so every SNS_N of the sine series vanishes there, no matter what ff does; each cos⁡kx\cos kx has zero slope at both walls, so every SNS_N of the cosine series has zero slope there. That is not a flaw but the point: if the heat problem says the rod is held at 00, the solution built from sines obeys that at every step.

The third row is a genuine mixed problem. Orthogonality holds: for half-integers m≠nm \ne n, ∫0πsin⁡mxsin⁡nx dx=12[sin⁡(m−n)πm−n−sin⁡(m+n)πm+n]=0\int_0^\pi \sin mx\sin nx\,dx = \tfrac12\bigl[\tfrac{\sin(m-n)\pi}{m-n} - \tfrac{\sin(m+n)\pi}{m+n}\bigr] = 0, because m−nm - n and m+nm + n are integers; and ∫0πsin⁡2mx dx=π/2\int_0^\pi \sin^2 mx\,dx = \pi/2 again. So ck=2π∫0πfsin⁡((k−12)x)dxc_k = \frac2\pi\int_0^\pi f\sin\bigl((k - \tfrac12)x\bigr)dx. Geometrically this is an extension that is odd about 00 and even about π\pi, with period 4π4\pi. For f=xf = x the integral is 2π∫0πxsin⁡(mx) dx\frac2\pi\int_0^\pi x\sin(mx)\,dx with m=k−12m = k - \frac12; since cos⁡mπ=0\cos m\pi = 0 and sin⁡mπ=(−1)k+1\sin m\pi = (-1)^{k+1} it equals 2π⋅(−1)k+1(k−1/2)2\frac{2}{\pi}\cdot\frac{(-1)^{k+1}}{(k-1/2)^2}, and the sim returns c1,…,c5=2.546479, −0.282942, 0.101859, −0.051969, 0.031438c_1, \dots, c_5 = 2.546479,\ -0.282942,\ 0.101859,\ -0.051969,\ 0.031438. This series converges at the 1/k21/k^2 rate with the best constant of the three here: at N=39N = 39 its error is 0.001070.00107, against 0.001450.00145 for the cosine series, because its extension has one corner per period of 4π4\pi instead of two per 2π2\pi.

What the wall values say. Take f=xf = x, N=7N = 7. The sine sum has S7(π)=0S_7(\pi) = 0 although f(π)=πf(\pi) = \pi: at the jump of the odd extension the series sits at the midpoint of the two sides (last lesson, from memory). Its slope at the wall is S7′(π)=−14.000=−2NS_7'(\pi) = -14.000 = -2N, growing without bound as NN increases while f′=1f' = 1. The cosine sum has S7′(0)=S7′(π)=0.000S_7'(0) = S_7'(\pi) = 0.000 although f′=1f' = 1, and its values are S7(0)=0.0792S_7(0) = 0.0792 and S7(π)=3.0624S_7(\pi) = 3.0624, creeping toward the true 00 and π\pi. In both cases the series converges to ff in the interior and in the mean-square sense, but the derivative of the series does not converge to f′f' at the wall. For heat flow the flux is −kux-k u_x, so a method that reads the wall flux off a Fourier sum with the wrong basis gets nonsense even when the temperature looks good. Hence the rule: choose the basis whose modes satisfy the boundary condition you actually have, and read fluxes from the equation, not by differentiating the sum.

Worked example 2: the constant and the parabola, step by step

f=1f = 1. Sine: bk=2π[−cos⁡kxk]0π=2(1−(−1)k)kπb_k = \frac2\pi\bigl[-\frac{\cos kx}{k}\bigr]_0^\pi = \frac{2(1 - (-1)^k)}{k\pi}, so bk=4/(kπ)b_k = 4/(k\pi) for odd kk: 1.273240, 0, 0.424413, 0, 0.2546481.273240,\ 0,\ 0.424413,\ 0,\ 0.254648 in the sim. Cosine: a0=2a_0 = 2 and ak=2π∫0πcos⁡kx dx=0a_k = \frac2\pi\int_0^\pi\cos kx\,dx = 0 for k≥1k \ge 1, so the series is a0/2=1a_0/2 = 1 and the sim’s coefficients a1,…,a5a_1, \dots, a_5 are 00 to six digits. A constant satisfies the Neumann condition, so Neumann’s basis represents it exactly.

f=x(π−x)f = x(\pi - x). Odd extension: u=x(π−x)u = x(\pi - x), u′=π−2xu' = \pi - 2x, u′′=−2u'' = -2. Integrate ∫0πusin⁡kx dx\int_0^\pi u\sin kx\,dx by parts twice; the boundary terms vanish because u(0)=u(π)=0u(0) = u(\pi) = 0, leaving −1k2∫0πu′′sin⁡kx dx=2k2∫0πsin⁡kx dx=2(1−(−1)k)k3-\frac{1}{k^2}\int_0^\pi u''\sin kx\,dx = \frac{2}{k^2}\int_0^\pi\sin kx\,dx = \frac{2(1 - (-1)^k)}{k^3}, hence bk=2π⋅2(1−(−1)k)k3=8πk3b_k = \frac2\pi\cdot\frac{2(1 - (-1)^k)}{k^3} = \frac{8}{\pi k^3} for odd kk. At x=π/2x = \pi/2, with sin⁡(kπ/2)=(−1)(k−1)/2\sin(k\pi/2) = (-1)^{(k-1)/2} for odd kk, the series says π24=8π(1−127+1125−⋯ )\frac{\pi^2}{4} = \frac8\pi\bigl(1 - \frac1{27} + \frac1{125} - \cdots\bigr), which sums the alternating series to π3/32\pi^3/32 (the next lesson, 8.5 Convergence & the Gibbs Phenomenon, makes the pointwise claim honest; the continuity of the extension is what justifies it, from memory).

Computing it

🐍 PythonLab: sine and cosine series of f = x on [0, pi]
⌘/Ctrl + Enter

Now build the half-range machinery yourself. The three bases are supplied through a single function mode; you write the projection, the partial sum and the error.

🧪 Coding exerciseExercise: half-range coefficients, partial sums and rms error
⌘/Ctrl + Enter

What comes next

We can now do the first half of every classical PDE problem on a bounded interval: pick the basis the walls dictate, and project the initial data onto it. Two things are still unproved. One is the convergence claim: we have seen in the sim that the series converges in the mean-square sense and that jumps leave a stubborn overshoot, but not where the series converges pointwise, which is the business of 8.5 Convergence & the Gibbs Phenomenon. The other is what the series are for. The next lesson in the build order, 9.3 Solving the Heat Equation: Separation of Variables, puts them to work: with u(0,t)=u(π,t)=0u(0, t) = u(\pi, t) = 0 the solution of the heat equation is ∑bke−k2tsin⁡kx\sum b_k e^{-k^2 t}\sin kx, each sine mode decaying at its own rate k2k^2 (9.2 The Heat (Diffusion) Equation derived the equation). Because high kk dies fastest, the 1/k1/k tail we complained about above vanishes the instant t>0t \gt 0.

Concept checks

✅ Concept check

A rod on $[0, \pi]$ has $u(0) = 0$ at one end and an insulated end $u'(\pi) = 0$. Which functions should the solution be expanded in?

✅ Concept check

For $f(x) = x$ on $[0, \pi]$, why does the sine series converge so much more slowly than the cosine series?

✅ Concept check

For $f = 1$ on $[0, \pi]$, what is the sine coefficient $b_1$? Give a number to four decimals.

✅ Concept check

The cosine partial sums $S_N$ of $f(x) = x$ on $[0, \pi]$ always have $S_N'(0) = 0$, although $f'(0) = 1$. What does this tell us?

Problems

✏️ Pen & paperConstant on a half interval●○○

Find the sine series and the cosine series of f(x)=1f(x) = 1 on (0,π)(0, \pi). Which extension is the square wave, and why does the other series need only one term?

Show worked solution

Sine: bk=2π∫0πsin⁡kx dx=2kπ(1−(−1)k)b_k = \frac2\pi\int_0^\pi \sin kx\,dx = \frac{2}{k\pi}(1 - (-1)^k), so 1=4π∑k oddsin⁡kxk1 = \frac4\pi\sum_{k\text{ odd}}\frac{\sin kx}{k}; this is the odd extension, a square wave of height ±1\pm1. Cosine: a0=2a_0 = 2 and ak=2π∫0πcos⁡kx dx=0a_k = \frac2\pi\int_0^\pi\cos kx\,dx = 0 for k≥1k \ge 1, so the series is just 11. The even extension of a constant is the same constant, so it has no jump and no corner; a numerical quadrature gives b1=1.273240b_1 = 1.273240 and a1=0a_1 = 0.

✏️ Pen & paperThe mixed series of $x$●●○

Show that sin⁡((k−12)x)\sin\bigl((k - \tfrac12)x\bigr), k≥1k \ge 1, are the eigenfunctions of −y′′=λy-y'' = \lambda y with y(0)=0y(0) = 0 and y′(π)=0y'(\pi) = 0, and find the coefficients for f(x)=xf(x) = x on [0,π][0, \pi].

Show worked solution

For λ=ω2>0\lambda = \omega^2 \gt 0 the solution vanishing at 00 is y=sin⁡ωxy = \sin\omega x, and y′(π)=ωcos⁡ωπ=0y'(\pi) = \omega\cos\omega\pi = 0 requires ωπ=(k−12)π\omega\pi = (k - \tfrac12)\pi, i.e. ω=k−12\omega = k - \tfrac12. (The cases λ≤0\lambda \le 0 give only y=0y = 0.) Orthogonality and ∥yk∥2=π/2\|y_k\|^2 = \pi/2 were shown above. With m=k−12m = k - \tfrac12, ck=2π∫0πxsin⁡mx dx=2π[−xcos⁡mxm+sin⁡mxm2]0π=2π⋅sin⁡mπm2c_k = \frac2\pi\int_0^\pi x\sin mx\,dx = \frac2\pi\Bigl[-\frac{x\cos mx}{m} + \frac{\sin mx}{m^2}\Bigr]_0^\pi = \frac{2}{\pi}\cdot\frac{\sin m\pi}{m^2}, since cos⁡mπ=0\cos m\pi = 0. And sin⁡(mπ)=sin⁡(kπ−π/2)=(−1)k+1\sin(m\pi) = \sin(k\pi - \pi/2) = (-1)^{k+1}. So ck=2(−1)k+1π(k−1/2)2c_k = \frac{2(-1)^{k+1}}{\pi(k - 1/2)^2}: c1=8/π=2.546479c_1 = 8/\pi = 2.546479, c2=−8/(9π)=−0.282942c_2 = -8/(9\pi) = -0.282942, in agreement with the sim.

✏️ Pen & paperA sum from the parabola●●○

Using f(x)=x(π−x)f(x) = x(\pi - x) and its sine series bk=8/(πk3)b_k = 8/(\pi k^3) (kk odd), evaluate the series at x=π/2x = \pi/2 to find ∑n≥0(−1)n/(2n+1)3\sum_{n \ge 0} (-1)^n/(2n + 1)^3. Then compute the first four partial sums to see how fast it converges.

Show worked solution

At x=π/2x = \pi/2, f=π2/4f = \pi^2/4, and sin⁡(kπ/2)=(−1)n\sin(k\pi/2) = (-1)^n for k=2n+1k = 2n + 1. So π24=8π∑n≥0(−1)n(2n+1)3\frac{\pi^2}{4} = \frac8\pi\sum_{n\ge0}\frac{(-1)^n}{(2n + 1)^3}, i.e. the sum equals π3/32=0.968946\pi^3/32 = 0.968946. Partial sums: 1, 0.962963, 0.970963, 0.9680481,\ 0.962963,\ 0.970963,\ 0.968048. They oscillate around the limit with an error shrinking like 1/k31/k^3, the same decay as the coefficients.

✏️ Pen & paperAn insulated rod, and a puzzle about the end slope●●●

A rod of length L=1L = 1 is insulated at both ends and starts with temperature f(x)=xf(x) = x. (a) Find the cosine series f=a02+∑akcos⁡kπxf = \frac{a_0}{2} + \sum a_k\cos k\pi x. (b) What temperature does the rod approach as t→∞t \to \infty? (c) The series has zero slope at x=0x = 0 but f′(0)=1f'(0) = 1. Explain why this is not a contradiction.

Show worked solution

(a) With the scaled formulas, ak=2∫01xcos⁡kπx dx=2[xsin⁡kπxkπ+cos⁡kπxk2π2]01=2((−1)k−1)k2π2a_k = 2\int_0^1 x\cos k\pi x\,dx = 2\Bigl[\frac{x\sin k\pi x}{k\pi} + \frac{\cos k\pi x}{k^2\pi^2}\Bigr]_0^1 = \frac{2((-1)^k - 1)}{k^2\pi^2}, so ak=−4k2π2a_k = -\dfrac{4}{k^2\pi^2} for odd kk and 00 for even kk, and a0=2∫01x dx=1a_0 = 2\int_0^1 x\,dx = 1. Thus f=12−4π2(cos⁡πx+cos⁡3πx9+⋯ )f = \frac12 - \frac{4}{\pi^2}\bigl(\cos\pi x + \frac{\cos 3\pi x}{9} + \cdots\bigr), with a1=−0.405285a_1 = -0.405285. (b) The nonconstant modes decay (their eigenvalues are (kπ)2>0(k\pi)^2 \gt 0), the constant mode does not, so the rod tends to the average temperature a0/2=12a_0/2 = \tfrac12: an insulated rod keeps its heat. (c) Every finite sum of cosines has zero slope at the ends, while the series equals ff in the limit. The convergence is not uniform for the derivative: the terms of the differentiated series, 4π∑k oddsin⁡kπxk\frac{4}{\pi}\sum_{k\text{ odd}}\frac{\sin k\pi x}{k}, form a square wave, which equals 11 inside (0,1)(0, 1) and is 00 at the endpoints (midpoint of the jump). The true boundary condition ux=0u_x = 0 is satisfied by every partial sum, and the interior slope 11 appears as the limit of a series that is not uniformly convergent near the wall.

Key Takeaways

  • A function given on [0,π][0, \pi] has two natural expansions: reflect it oddly (fodd(−x)=−f(x)f_{\text{odd}}(-x) = -f(x)) to get the sine series bk=2π∫0πfsin⁡kxb_k = \frac2\pi\int_0^\pi f\sin kx, or evenly (f(∣x∣)f(|x|)) to get the cosine series ak=2π∫0πfcos⁡kxa_k = \frac2\pi\int_0^\pi f\cos kx, with a0/2a_0/2 the average of ff. On [0,L][0, L] replace kxkx by kπx/Lk\pi x/L and 2/π2/\pi by 2/L2/L.
  • Boundary conditions choose the basis: Dirichlet ends give sines, Neumann ends cosines, and u(0)=0u(0) = 0 with u′(π)=0u'(\pi) = 0 gives sin⁡((k−12)x)\sin((k - \tfrac12)x) with λ=(k−12)2\lambda = (k - \tfrac12)^2. Every partial sum inherits the boundary condition of its modes.
  • Coefficient decay is the smoothness of the extension. The odd extension is continuous only if f(0)=f(π)=0f(0) = f(\pi) = 0; the even extension is always continuous but has a corner unless f′f' vanishes at the walls.
  • For f=xf = x at N=39N = 39 the rms errors are 0.22500.2250 (sine), 0.001450.00145 (cosine) and 0.001070.00107 (mixed); for f=x(π−x)f = x(\pi - x) they are 0.000060.00006 (sine) and 0.004740.00474 (cosine); for f=1f = 1 the cosine series is exact and the sine series has 0.10060.1006 and a Gibbs maximum of 1.17921.1792.
  • A partial sum of a sine series is 00 at the walls and one of a cosine series has zero slope there, for every NN. The series converges to ff in the interior but its derivative does not converge to f′f' at the wall (for f=xf = x, N=7N = 7: slope −14.000=−2N-14.000 = -2N at x=πx = \pi for the sine sum).
  • Spectral flow solvers use sine transforms for wall-normal velocity and cosine transforms for pressure-like quantities with zero normal gradient (from memory).
  • The next row in the build order, 9.3 Solving the Heat Equation: Separation of Variables, turns this into the solution of the heat equation, one decaying mode at a time; pointwise convergence and the Gibbs phenomenon proper wait for 8.5 Convergence & the Gibbs Phenomenon.
Finished this lesson?

Mark it complete to track your progress (saved in this browser). Reading every section does this for you.

Where this leads

These later lessons build directly on this one: