Fourier Sine and Cosine Series

A Fourier sine series or Fourier cosine series represents a function given only on 0 < x < L. Extend f as an odd function to get a sine series, or as an even function to get a cosine series. These half-range expansions are the form used to solve the heat and wave equations.

Before this lesson: Fourier Series, Even and Odd Functions and Integration by Parts

Why use half-range series?

In a physics problem, a function usually lives on a finite interval, such as the temperature along a rod of length L. It has no period at all. A Fourier series needs a function with period 2L, so first you must decide how f behaves on −L < x < 0.

There are two natural choices. Reflect the graph across the y-axis to get the even extension, or rotate it about the origin to get the odd extension. Then repeat with period 2L. On 0 < x < L, both extensions match f, so both series represent f there.

Graph for x from -6 to 6. The thick dark gray segment is f(x) = x from (0, 0) to (2, 2). The solid blue even extension is a triangle wave that goes up and down between 0 and 2 with peaks at x = -6, -2, 2 and 6, so it has no jumps. The dashed orange odd extension is a sawtooth that rises from -2 to 2 on each interval of length 4 and then drops, so it jumps at x = -6, -2, 2 and 6.
The even extension of f(x) = x on (0, 2) (solid blue) is a triangle wave with no jumps; the odd extension (dashed orange) is a sawtooth that jumps at x = ±2 and ±6.

Fourier sine and cosine series formulas

An odd function has every aₙ = 0, and an even function has every bₙ = 0. Using the shortcuts for even and odd functions from the Fourier series lesson gives two half-range series:

\text{Sine series: } f(x) \sim \sum_{n=1}^{\infty} b_n\sin\frac{n\pi x}{L},\qquad b_n = \frac{2}{L}\int_0^L f(x)\sin\frac{n\pi x}{L}\,dx
\text{Cosine series: } f(x) \sim \frac{a_0}{2} + \sum_{n=1}^{\infty} a_n\cos\frac{n\pi x}{L},\qquad a_n = \frac{2}{L}\int_0^L f(x)\cos\frac{n\pi x}{L}\,dx

Choosing the sine or the cosine series

Use theWhenAt x = 0 and x = L the series gives
sine seriesf should be 0 at both ends, such as a string tied down at both ends or a rod with ends held at 0°0, since every sin(nπx/L) is 0 there
cosine seriesf should have zero slope at both ends, such as a rod with insulated endsf(0⁺) and f(L⁻), since the even extension has no jump at the ends

These are exactly the eigenfunctions from boundary value problems: sin(nπx/L) for y(0) = y(L) = 0, and cos(nπx/L) for y′(0) = y′(L) = 0.

How to find a half-range expansion

  1. Decide which series you need, and identify L.
  2. For a sine series, compute bₙ = (2/L)∫₀ᴸ f(x) sin(nπx/L) dx.
  3. For a cosine series, compute a₀ = (2/L)∫₀ᴸ f(x) dx first, then aₙ for n ≥ 1.
  4. Simplify with cos nπ = (−1)ⁿ and sin nπ = 0, then split into odd and even n if needed.

Fourier sine and cosine series examples

Example 1: Sine series of a constant

Find the Fourier sine series of f(x) = 1 on 0 < x < π.

b_n = \frac{2}{\pi}\int_0^{\pi}\sin nx\,dx

Sine series with L = π.

= \frac{2}{\pi}\left[-\frac{\cos nx}{n}\right]_0^{\pi}

Antiderivative of sin nx.

= \frac{2\left(1 - (-1)^n\right)}{n\pi}

cos nπ = (−1)ⁿ and cos 0 = 1.

b_n = \frac{4}{n\pi} \text{ (n odd)},\quad b_n = 0 \text{ (n even)}

1 − (−1)ⁿ is 2 for odd n and 0 for even n.

Answer: 1 ∼ (4/π)(sin x + sin 3x/3 + sin 5x/5 + ⋯) for 0 < x < π. The odd extension of 1 is the square wave, so this matches the square wave series. At x = 0 and x = π the series gives 0, not 1.

Example 2: Cosine series of f(x) = x

Find the Fourier cosine series of f(x) = x on 0 < x < 2.

a_0 = \frac{2}{2}\int_0^2 x\,dx = 2

L = 2, so 2/L = 1. Then a₀/2 = 1.

a_n = \int_0^2 x\cos\frac{n\pi x}{2}\,dx

Cosine coefficient for n ≥ 1.

= \left[\frac{2x}{n\pi}\sin\frac{n\pi x}{2}\right]_0^2 - \frac{2}{n\pi}\int_0^2\sin\frac{n\pi x}{2}\,dx

Integration by parts with u = x and dv = cos(nπx/2) dx.

= 0 - \frac{2}{n\pi}\cdot\frac{2\left(1 - (-1)^n\right)}{n\pi}

sin nπ = 0; the sine integral is (2/(nπ))(1 − cos nπ).

a_n = \frac{4\left((-1)^n - 1\right)}{n^2\pi^2}

Multiply and move the minus sign inside.

a_n = -\frac{8}{n^2\pi^2} \text{ (n odd)},\quad a_n = 0 \text{ (n even)}

(−1)ⁿ − 1 is −2 for odd n.

Answer: x ∼ 1 − (8/π²)(cos(πx/2) + cos(3πx/2)/9 + cos(5πx/2)/25 + ⋯) for 0 ≤ x ≤ 2. The even extension is the triangle wave in the graph, which has no jumps, so the series equals x even at the ends.

Example 3: Sine series of the same function

Find the Fourier sine series of f(x) = x on 0 < x < 2, and compare it with Example 2.

b_n = \int_0^2 x\sin\frac{n\pi x}{2}\,dx

Sine series with L = 2, so 2/L = 1.

= \left[-\frac{2x}{n\pi}\cos\frac{n\pi x}{2}\right]_0^2 + \frac{2}{n\pi}\int_0^2\cos\frac{n\pi x}{2}\,dx

Integrate by parts with u = x and dv = sin(nπx/2) dx.

= -\frac{4\cos n\pi}{n\pi} + 0

The cosine integral is (2/(nπ)) sin nπ = 0.

b_n = \frac{4(-1)^{n+1}}{n\pi}

cos nπ = (−1)ⁿ.

Answer: x ∼ (4/π)(sin(πx/2) − sin(πx)/2 + sin(3πx/2)/3 − ⋯) for 0 < x < 2. These coefficients shrink like 1/n, while the cosine coefficients in Example 2 shrink like 1/n². The odd extension jumps at x = 2, and jumps make a series converge more slowly.

Example 4: Sine series of f(x) = x(π − x)

Find the Fourier sine series of f(x) = x(π − x) on 0 < x < π.

b_n = \frac{2}{\pi}\left(\pi\int_0^{\pi} x\sin nx\,dx - \int_0^{\pi} x^2\sin nx\,dx\right)

Expand x(π − x) = πx − x² and split the integral.

\int_0^{\pi} x\sin nx\,dx = \frac{\pi(-1)^{n+1}}{n}

Integrate by parts, as in the Fourier series lesson.

\int_0^{\pi} x^2\sin nx\,dx = -\frac{\pi^2(-1)^n}{n} + \frac{2}{n}\int_0^{\pi} x\cos nx\,dx

Integrate by parts with u = x².

\int_0^{\pi} x\cos nx\,dx = \frac{(-1)^n - 1}{n^2}

Integrate by parts once more.

\pi\cdot\frac{\pi(-1)^{n+1}}{n} + \frac{\pi^2(-1)^n}{n} - \frac{2\left((-1)^n - 1\right)}{n^3} = \frac{2\left(1 - (-1)^n\right)}{n^3}

Subtract; the π² terms cancel.

b_n = \frac{4\left(1 - (-1)^n\right)}{\pi n^3}

Multiply by 2/π.

b_n = \frac{8}{\pi n^3} \text{ (n odd)},\quad b_n = 0 \text{ (n even)}

1 − (−1)ⁿ is 2 for odd n.

Answer: x(π − x) ∼ (8/π)(sin x + sin 3x/27 + sin 5x/125 + ⋯). The first term alone is very close: at x = π/2 it gives 8/π ≈ 2.546, while f(π/2) = π²/4 ≈ 2.467.

Example 5: An insulated rod (word problem)

A metal rod 10 cm long has insulated ends. At first, the left half (0 < x < 5) is at 50 °C and the right half is at 0 °C. Insulated ends call for a cosine series. Find the cosine series of the starting temperature, and find a₁ and a₃.

a_0 = \frac{2}{10}\int_0^5 50\,dx = \frac{2}{10}\cdot 250 = 50

L = 10; f is 0 on (5, 10).

\frac{a_0}{2} = 25

The average starting temperature.

a_n = \frac{2}{10}\int_0^5 50\cos\frac{n\pi x}{10}\,dx = 10\left[\frac{10}{n\pi}\sin\frac{n\pi x}{10}\right]_0^5

Simplify (2/10)(50) = 10 and integrate.

a_n = \frac{100}{n\pi}\sin\frac{n\pi}{2}

Evaluate at x = 5 and x = 0.

a_1 = \frac{100}{\pi} \approx 31.83,\quad a_3 = -\frac{100}{3\pi} \approx -10.61

sin(π/2) = 1 and sin(3π/2) = −1; every even n gives 0.

Answer: f(x) ∼ 25 + (100/π)(cos(πx/10) − cos(3πx/10)/3 + cos(5πx/10)/5 − ⋯). The constant 25 °C is the average temperature. With insulated ends no heat escapes, so the rod slowly settles to 25 °C everywhere, as the Heat Equation lesson shows.

Common mistakes

MistakeExample of the errorFix
Using 1/L instead of 2/LWriting bₙ = (1/π)∫₀^π sin nx dx in Example 1Half-range formulas use 2/L, because the integral covers only half a period.
Integrating from −L to LUsing f(x) = x on (−2, 2) for the cosine series in Example 2f is given only on (0, L); integrate from 0 to L.
Forgetting the a₀/2 term in a cosine seriesWriting x ∼ −(8/π²) Σ cos(nπx/2)/n²Compute a₀ separately; here a₀/2 = 1.
Expecting the sine series to equal f at the endsSaying the series in Example 1 gives 1 at x = 0Every sine term is 0 at x = 0 and x = L.
Picking the series that does not fit the boundary conditionsUsing a sine series for a rod with insulated endsFixed values of 0 at the ends need sines; insulated ends need cosines.
Dropping the sign of sin(nπ/2)Writing a₃ = +100/(3π) in Example 5sin(nπ/2) cycles 1, 0, −1, 0, so the odd terms alternate in sign.

Related ideas

Solving partial differential equations

Separating variables in the heat equation uₜ = kuₓₓ with u = 0 at both ends leads to the eigenfunctions sin(nπx/L). The starting temperature must then be written as a sine series, and each term decays at its own rate. That is the next lesson, Heat Equation.

Speed of convergence

Smooth extensions converge fast. In Example 4 the odd extension of x(π − x) has no corners at the ends, so its coefficients shrink like 1/n³, much faster than the 1/n of a series with jumps.

Practice problems

  1. Find the Fourier sine series of f(x) = 3 on 0 < x < π.
  2. Find the Fourier cosine series of f(x) = 3 on 0 < x < π.
  3. Find the Fourier cosine series of f(x) = x on 0 < x < π.
  4. Find the Fourier sine series of f(x) = x on 0 < x < π.
  5. Use Example 4 at x = π/2 to find 1 − 1/27 + 1/125 − 1/343 + ⋯.
  6. What value does the sine series in Example 1 give at x = 0 and at x = π?
  7. What value does the cosine series in Example 2 give at x = 2? At x = −1?
  8. Find the Fourier sine series of f(x) = cos x on 0 < x < π.
  9. A rod 20 cm long has insulated ends. Its left half starts at 40 °C and its right half at 0 °C. Find a₀/2 and a₁ in its cosine series.
  10. A string of length 1 m is pulled into the shape f(x) = x for 0 < x < 1. Find the sine series coefficients bₙ and b₁.
Show answers

1.

b_n = \frac{2}{\pi}\int_0^{\pi} 3\sin nx\,dx = \frac{6\left(1 - (-1)^n\right)}{n\pi}

Three times Example 1.

Answer: 3 ∼ (12/π)(sin x + sin 3x/3 + sin 5x/5 + ⋯)

2.

a_0 = \frac{2}{\pi}\int_0^{\pi} 3\,dx = 6

So a₀/2 = 3.

a_n = \frac{2}{\pi}\int_0^{\pi} 3\cos nx\,dx = \frac{6\sin n\pi}{n\pi} = 0

sin nπ = 0.

Answer: the cosine series is just 3; a constant is already an even function

3.

a_0 = \frac{2}{\pi}\int_0^{\pi} x\,dx = \pi

So a₀/2 = π/2.

a_n = \frac{2}{\pi}\cdot\frac{(-1)^n - 1}{n^2}

Use ∫₀^π x cos nx dx from Example 4.

Answer: x ∼ π/2 − (4/π)(cos x + cos 3x/9 + cos 5x/25 + ⋯)

4.

b_n = \frac{2}{\pi}\cdot\frac{\pi(-1)^{n+1}}{n} = \frac{2(-1)^{n+1}}{n}

Use ∫₀^π x sin nx dx from Example 4.

Answer: x ∼ 2(sin x − sin 2x/2 + sin 3x/3 − ⋯)

5.

\frac{\pi^2}{4} = \frac{8}{\pi}\left(1 - \frac{1}{27} + \frac{1}{125} - \cdots\right)

At x = π/2, sin(nπ/2) is 1, −1, 1, … for n = 1, 3, 5, …; f(π/2) = π²/4.

1 - \frac{1}{27} + \frac{1}{125} - \cdots = \frac{\pi^2}{4}\cdot\frac{\pi}{8} = \frac{\pi^3}{32}

Multiply both sides by π/8.

Answer: π³/32 ≈ 0.9689

6.

\sin 0 = 0,\quad \sin n\pi = 0

Every term of a sine series is 0 at both ends.

Answer: 0 at both ends (the average of 1 and −1 for the odd extension)

7.

\text{even extension at } x = 2:\ 2,\qquad \text{at } x = -1:\ f(1) = 1

The triangle wave is continuous, and it is even, so its value at −1 equals its value at 1.

Answer: 2 at x = 2, and 1 at x = −1

8.

b_n = \frac{2}{\pi}\int_0^{\pi}\cos x\sin nx\,dx

Sine series with L = π.

\cos x\sin nx = \frac{1}{2}\left[\sin(n+1)x + \sin(n-1)x\right]

Product-to-sum identity.

\int_0^{\pi}\cos x\sin nx\,dx = \frac{\left(1 + (-1)^n\right)n}{n^2 - 1}

Integrate each sine for n ≥ 2 and combine the fractions; the integral is 0 for n = 1.

b_n = \frac{4n}{\pi(n^2 - 1)} \text{ (n even)},\quad b_n = 0 \text{ (n odd)}

1 + (−1)ⁿ is 2 for even n.

Answer: cos x ∼ (8/(3π)) sin 2x + (16/(15π)) sin 4x + ⋯

9.

a_0 = \frac{2}{20}\int_0^{10} 40\,dx = 40

So a₀/2 = 20 °C.

a_n = \frac{2}{20}\int_0^{10} 40\cos\frac{n\pi x}{20}\,dx = \frac{80}{n\pi}\sin\frac{n\pi}{2}

Same steps as Example 5 with L = 20.

Answer: a₀/2 = 20 °C and a₁ = 80/π ≈ 25.46 °C

10.

b_n = 2\int_0^1 x\sin n\pi x\,dx = \frac{2(-1)^{n+1}}{n\pi}

Sine series with L = 1; integrate by parts.

Answer: bₙ = 2(−1)ⁿ⁺¹/(nπ), so b₁ = 2/π ≈ 0.637

Fourier sine and cosine series FAQ

What is a half-range Fourier series?

It is a Fourier sine series or cosine series for a function given only on 0 < x < L. You extend the function as odd or even, so only half of the usual coefficients are needed.

When do you use a sine series instead of a cosine series?

Use a sine series when the function should be 0 at both ends, such as a string fixed at both ends. Use a cosine series when the slope should be 0 at both ends, such as a rod with insulated ends.

Why is the formula 2/L instead of 1/L?

The full formula integrates over −L to L and divides by L. For an even or odd extension, the two halves contribute equal amounts, so the integral from 0 to L is doubled.

Does a Fourier sine series equal f at the endpoints?

Not unless f is 0 there. Every term sin(nπx/L) is 0 at x = 0 and x = L, so the sine series always gives 0 at the ends.

Summary

  • A function on 0 < x < L can be extended as odd (sine series) or even (cosine series).
  • bₙ = (2/L)∫₀ᴸ f(x) sin(nπx/L) dx and aₙ = (2/L)∫₀ᴸ f(x) cos(nπx/L) dx.
  • Use sines when f is 0 at the ends and cosines when the ends are insulated.
  • The cosine series includes the constant a₀/2, the average of f.
  • Smoother extensions give coefficients that shrink faster.

Previous lesson: Fourier Series

Next lesson: Heat Equation

Back to the Differential Equations Index