This page is a shooting range . The parent note gave you the two formulas; here we fire every kind of function at them so no exam problem can surprise you. Before any example, we build a map of all the cases — then we knock them out one by one.
Intuition Why a "scenario matrix" first
A formula is only half the skill. The other half is recognising which situation you are in the moment you read the question. If you have already seen every type of input — a straight line, a constant, a piecewise function, a function that does not vanish at the ends, a limiting/degenerate case — then solving is just plugging into machinery you trust. So first we list the cases. Then we cover each.
Two symbols we will lean on constantly, defined in plain words so nothing is assumed:
Definition The two coefficients (in words)
b n = L 2 ∫ 0 L f ( x ) sin L nπ x d x — the "amount of the n -th sine wiggle " hiding inside f . Sine waves are zero at both ends x = 0 and x = L .
a n = L 2 ∫ 0 L f ( x ) cos L nπ x d x — the "amount of the n -th cosine wiggle ". Cosine waves have zero slope (flat top) at both ends.
2 a 0 = L 1 ∫ 0 L f ( x ) d x — the average height of f across [ 0 , L ] .
Here L is just the right-hand end of the interval [ 0 , L ] . Nothing else is hidden.
Every half-range problem you can be handed falls into one of these cells. The last column names the example that clears it. Figure s01 draws the heart of the whole page: the same function f ( x ) = x mirrored two ways. Look at it now — the left panel (coral solid + lavender dashed) shows the odd mirror, which has a violent jump at the right end (a sawtooth); the right panel (coral solid + mint dashed) shows the even mirror ∣ x ∣ , which only has a gentle corner . That single contrast — jump vs corner — is why sine coefficients die slowly (1/ n ) and cosine coefficients die fast (1/ n 2 ). Keep glancing back at this picture as you read Cells A, B and H.
#
Case class
What makes it tricky
Cleared by
A
Straight line f = x , sine
odd extension has a jump at the end → slow 1/ n decay
Ex 1
B
Straight line f = x , cosine
even extension is a corner → faster 1/ n 2 ; needs a 0
Ex 2
C
Constant f = c , sine vs cosine
cosine is trivial ; sine is a subtle non-zero series
Ex 3
D
Piecewise (split-domain) function
integrate over each piece separately (sine and cosine)
Ex 4, Ex 4b
E
Function that does NOT vanish at the ends
endpoint value ≠ 0 → midpoint (Dirichlet) surprise
Ex 5
F
Even-power polynomial f = x 2 , cosine
double integration by parts; a 0 = 0
Ex 6
G
Real-world word problem (heated/insulated rod)
translate physics → pick sine or cosine BC
Ex 7
H
Exam-twist / limiting behaviour
n → ∞ decay rate + endpoint convergence value
Ex 8
We also cover the two degenerate inputs every topic must handle:
n = 0 (the average term) — appears in Ex 2, 4b, 6, 7.
endpoint values x = 0 and x = L where the series may not equal f — Ex 5, 8.
Worked example Example 1 —
f ( x ) = x on [ 0 , π ] , half-range sine
Forecast first: the odd mirror of a rising line is a sawtooth (up-ramp, then a sudden drop) — exactly the left panel of figure s01 . Guess: will the coefficients die fast or slow?
Here L = π , so L nπ x = n x and b n = π 2 ∫ 0 π x sin ( n x ) d x .
Integrate by parts. Why this step? We have polynomial × trig; parts trades the x away, leaving a pure trig integral we can finish.
∫ 0 π x sin ( n x ) d x = [ − n x c o s n x ] 0 π + n 1 ∫ 0 π cos n x d x = − n π c o s nπ + 0.
Kill the leftover integral. Why zero? ∫ 0 π cos n x d x = n s i n nπ = 0 since sin ( nπ ) = 0 for every integer n .
Use cos nπ = ( − 1 ) n . Why? Cosine at whole multiples of π flips + 1 , − 1 , + 1 , …
b n = π 2 ( − n π ( − 1 ) n ) = n 2 ( − 1 ) n + 1 .
x = 2 n = 1 ∑ ∞ n ( − 1 ) n + 1 sin ( n x ) , 0 < x < π .
Verify: plug x = 2 π : RHS = 2 ( 1 − 3 1 + 5 1 − ⋯ ) = 2 ⋅ 4 π = 2 π = f ( 2 π ) . ✓ Decay is ∼ 1/ n — slow , matching the sawtooth jump in figure s01. Forecast confirmed.
Worked example Example 2 —
f ( x ) = x on [ 0 , π ] , half-range cosine
Forecast: the even mirror of x is ∣ x ∣ — a "V" tent, no jump , only a corner (the right panel of figure s01 ). Guess: faster or slower decay than Ex 1?
Average term a 0 . Why separate? cos ( 0 ⋅ x ) = 1 , so the n = 0 term is special — it carries the mean.
a 0 = π 2 ∫ 0 π x d x = π 2 ⋅ 2 π 2 = π ⇒ 2 a 0 = 2 π . (The average of x on [ 0 , π ] is indeed π /2 . ✓)
Parts for a n . Why? Same polynomial×trig structure.
∫ 0 π x cos n x d x = [ n x s i n n x ] 0 π − n 1 ∫ 0 π sin n x d x = 0 + n 2 1 [ cos n x ] 0 π = n 2 ( − 1 ) n − 1 .
Split odd/even n . Why? ( − 1 ) n − 1 is 0 for even n , − 2 for odd n . So a n = − π n 2 4 (odd n ), 0 (even n ).
x = 2 π − π 4 k = 0 ∑ ∞ ( 2 k + 1 ) 2 cos (( 2 k + 1 ) x ) , 0 < x < π .
Verify at x = 0 : RHS = 2 π − π 4 ∑ ( 2 k + 1 ) 2 1 = 2 π − π 4 ⋅ 8 π 2 = 0 = f ( 0 ) . ✓ Decay ∼ 1/ n 2 — faster than Ex 1. Forecast confirmed: smooth corner beats a jump. (See Even and Odd Functions .)
Worked example Example 3 —
f ( x ) = c (a constant) on [ 0 , L ] , both series
Forecast: a constant is already flat. Which series is trivial, which is surprising?
Cosine side. Why trivial? The even mirror of a constant is the same constant — no wiggle needed.
2 a 0 = L 1 ∫ 0 L c d x = c , a n = L 2 ∫ 0 L c cos L nπ x d x = L 2 c ⋅ nπ L [ sin L nπ x ] 0 L = 0.
So the cosine series is just f = c . One term, done.
Sine side. Why non-trivial? The odd mirror of c is a square wave (up + c , down − c ) — full of wiggles.
b n = L 2 ∫ 0 L c sin L nπ x d x = L 2 c ⋅ nπ L [ − cos L nπ x ] 0 L = nπ 2 c ( 1 − cos nπ ) = nπ 2 c ( 1 − ( − 1 ) n ) .
This is nπ 4 c for odd n , 0 for even n .
c = π 4 c k = 0 ∑ ∞ 2 k + 1 1 sin L ( 2 k + 1 ) π x , 0 < x < L .
Verify (take c = 1 , L = π , x = 2 π ): RHS = π 4 ( 1 − 3 1 + 5 1 − ⋯ ) = π 4 ⋅ 4 π = 1 = c . ✓ A flat line hides an infinite pile of sines because we forced a jump at the ends.
Worked example Example 4 — piecewise
f , half-range sine , L = 2
f ( x ) = { x , 2 − x , 0 ≤ x ≤ 1 1 ≤ x ≤ 2 ( a symmetric "tent" ) .
Forecast: it rises then falls, peaking at x = 1 . Only odd multiples of the half should survive — guess why.
Split the integral at the corner. Why? The formula for f changes at x = 1 , so integrate each piece with its own rule. Write k n = 2 nπ for short.
b n = 2 2 I 1 ∫ 0 1 x sin 2 nπ x d x + I 2 ∫ 1 2 ( 2 − x ) sin 2 nπ x d x .
Parts on piece I 1 . Why? polynomial×trig. With u = x , d v = sin ( k n x ) d x :
I 1 = [ − k n x c o s k n x ] 0 1 + k n 1 ∫ 0 1 cos k n x d x = − k n c o s k n + k n 2 s i n k n .
Parts on piece I 2 . Why the same tool? Still polynomial×trig, now with u = 2 − x (so d u = − d x ):
I 2 = [ − k n ( 2 − x ) c o s k n x ] 1 2 − k n 1 ∫ 1 2 cos k n x d x = k n c o s k n − k n 2 s i n 2 k n − s i n k n .
Add and watch the boundary terms cancel. Why do they collapse? The two k n cos k n terms (from the corner x = 1 ) are equal and opposite, so they cancel ; and sin 2 k n = sin ( nπ ) = 0 . What survives is only the two sin k n / k n 2 interior pieces:
I 1 + I 2 = k n 2 s i n k n + k n 2 s i n k n = k n 2 2 s i n k n = ( nπ /2 ) 2 2 s i n 2 nπ = n 2 π 2 8 s i n 2 nπ .
Multiply by the prefactor 2 2 = 1 . Why 1? Here L 2 = 2 2 = 1 , so b n = I 1 + I 2 directly:
b n = n 2 π 2 8 sin 2 nπ .
Read sin 2 nπ . It is 0 for even n and ± 1 for odd n — so only odd harmonics appear (the tent is symmetric about its middle).
f ( x ) = π 2 8 k = 0 ∑ ∞ ( 2 k + 1 ) 2 ( − 1 ) k sin 2 ( 2 k + 1 ) π x , 0 < x < 2.
Verify at the peak x = 1 (should give f ( 1 ) = 1 ): sin 2 ( 2 k + 1 ) π = ( − 1 ) k , so RHS = π 2 8 ∑ ( 2 k + 1 ) 2 ( − 1 ) k ( − 1 ) k = π 2 8 ⋅ 8 π 2 = 1 . ✓
Worked example Example 4b —
same piecewise tent, half-range cosine , L = 2
The natural counterpart: expand the identical tent as a cosine series (what an insulated rod would need).
Forecast: cosine keeps a constant term = the tent's average height. The tent rises to 1 then falls, so its average should be 2 1 . Predict 2 a 0 = 2 1 .
Average term a 0 . Why first? n = 0 carries the mean, split across the two pieces.
a 0 = 2 2 [ ∫ 0 1 x d x + ∫ 1 2 ( 2 − x ) d x ] = [ 2 1 + 2 1 ] = 1 ⇒ 2 a 0 = 2 1 . (Matches the forecast ✓.)
a n in two pieces. Why split again? Same reason — the formula changes at x = 1 . Write k n = 2 nπ ; note cos 2 k n = cos ( nπ ) = ( − 1 ) n and sin 2 k n = sin ( nπ ) = 0 . With u -choices as in Ex 4:
∫ 0 1 x cos k n x d x = [ k n x s i n k n x ] 0 1 − k n 1 ∫ 0 1 sin k n x d x = k n s i n k n + k n 2 c o s k n − 1 ,
∫ 1 2 ( 2 − x ) cos k n x d x = [ k n ( 2 − x ) s i n k n x ] 1 2 + k n 1 ∫ 1 2 sin k n x d x = − k n s i n k n + k n 2 c o s k n − c o s 2 k n .
Add — the sin k n / k n terms cancel and cos 2 k n enters. Why? The two ± sin k n / k n boundary terms (corner x = 1 ) are equal and opposite, so they cancel. The surviving numerators are ( cos k n − 1 ) from the first piece and ( cos k n − cos 2 k n ) from the second. Add them and use cos 2 k n = ( − 1 ) n :
a n = k n 2 ( c o s k n − 1 ) + ( c o s k n − ( − 1 ) n ) = k n 2 2 c o s k n − 1 − ( − 1 ) n .
Simplify with − 1 − ( − 1 ) n . Why? For even n , − 1 − ( − 1 ) n = − 2 , giving numerator 2 cos k n − 2 = 2 ( cos 2 nπ − 1 ) . For odd n , − 1 − ( − 1 ) n = 0 and cos k n = cos 2 nπ = 0 , giving numerator 0 − 0 = 0 = 2 ( cos 2 nπ − 1 ) (since cos 2 nπ = 0 makes 2 ( 0 − 1 ) = − 2 ... let us be careful and just compute case by case below). In all cases the numerator equals 2 ( cos 2 nπ − 1 ) once we verify — but rather than trust that shortcut, read the three residue classes directly.
Read the three classes of n . Why three? cos 2 nπ and ( − 1 ) n together repeat every 4 . Using k n 2 = ( nπ /2 ) 2 = n 2 π 2 /4 so a factor 4 appears:
n ≡ 0 ( mod 4 ) : cos k n = 1 , ( − 1 ) n = 1 → numerator 2 ( 1 ) − 1 − 1 = 0 → a n = 0 .
n ≡ 2 ( mod 4 ) : cos k n = − 1 , ( − 1 ) n = 1 → numerator 2 ( − 1 ) − 1 − 1 = − 4 → a n = n 2 π 2 /4 − 4 = n 2 π 2 − 16 .
n odd: cos k n = 0 , ( − 1 ) n = − 1 → numerator 0 − 1 + 1 = 0 → a n = 0 .
So only n ≡ 2 ( mod 4 ) survive. Notice these three lines are exactly what n 2 π 2 8 ( cos 2 nπ − 1 ) produces (0 , − n 2 π 2 16 , 0 respectively), so we may write the compact form:
f ( x ) = 2 1 + n = 1 ∑ ∞ n 2 π 2 8 ( cos 2 nπ − 1 ) cos 2 nπ x , 0 < x < 2.
Verify at x = 1 (tent peak, cosine even-mirror is continuous, should give 1 ): only n ≡ 2 ( mod 4 ) contribute, cos 2 nπ ⋅ 1 = cos 2 nπ = − 1 there, and numerically summing gives 1.000 . ✓ Compare with Ex 4 — same function, two legitimate series; the choice is dictated by the boundary condition, not the function.
Worked example Example 5 —
f ( x ) = 1 on [ 0 , π ] , sine series, endpoint surprise
This is Cell C with c = 1 , L = π , but now we interrogate the endpoints — the case that trips everyone.
From Ex 3: 1 = π 4 k = 0 ∑ ∞ 2 k + 1 sin (( 2 k + 1 ) x ) for 0 < x < π .
Ask what the series gives at x = 0 . Why? Because f ( 0 ) = 1 , but every sin ( n ⋅ 0 ) = 0 , so the series sums to 0 , not 1. Contradiction?
Resolve with Dirichlet's midpoint rule. Why does this rule exist? At a jump of the periodic extension , a Fourier series converges to the average of the two sides . The odd square-wave jumps from − 1 (just left of 0) to + 1 (just right), so the series gives 2 − 1 + 1 = 0 . ✓ Not a bug — the rule. (See Dirichlet Conditions .)
Same at x = π . Jump from + 1 to − 1 , midpoint = 0 ; series gives 0 , not f ( π ) = 1 .
Verify the inside point x = 2 π : RHS = π 4 ( 1 − 3 1 + 5 1 − ⋯ ) = 1 . ✓
Take-away: write series equalities on the open interval 0 < x < π ; check ends via the midpoint rule.
Worked example Example 6 —
f ( x ) = x 2 on [ 0 , π ] , half-range cosine
Forecast: a parabola's even mirror is smooth (no corner value jump), so expect fast decay and a hefty average.
Average term. Why first? Again n = 0 is special.
a 0 = π 2 ∫ 0 π x 2 d x = π 2 ⋅ 3 π 3 = 3 2 π 2 ⇒ 2 a 0 = 3 π 2 .
Parts twice for a n . Why twice? Each parts drops the polynomial power by one; x 2 needs two rounds.
∫ 0 π x 2 cos n x d x = [ n x 2 s i n n x ] 0 π − n 2 ∫ 0 π x sin n x d x = 0 − n 2 ( − n π ( − 1 ) n ) = n 2 2 π ( − 1 ) n .
Assemble. a n = π 2 ⋅ n 2 2 π ( − 1 ) n = n 2 4 ( − 1 ) n .
x 2 = 3 π 2 + 4 n = 1 ∑ ∞ n 2 ( − 1 ) n cos ( n x ) , 0 < x < π .
Verify at x = π (parabola even-mirror is continuous, so should equal π 2 ): RHS = 3 π 2 + 4 ∑ n 2 ( − 1 ) n c o s ( nπ ) = 3 π 2 + 4 ∑ n 2 ( − 1 ) n ( − 1 ) n = 3 π 2 + 4 ⋅ 6 π 2 = π 2 . ✓ (Uses ∑ 1/ n 2 = π 2 /6 .)
Worked example Example 7 — insulated rod (word problem → pick the series)
"A rod 0 ≤ x ≤ L , L = π , has both ends insulated (no heat flows out: zero slope at the ends). Its initial temperature profile is f ( x ) = x . Which half-range series describes the initial state, and what is its steady-state (eventual uniform) temperature?"
Forecast: insulated = zero slope at ends = Neumann BC → we need functions flat at the ends → cosine . Guess the final temperature.
Translate physics to a series. Why cosine? Cosine waves have zero derivative at x = 0 , π , exactly matching insulated ends (see Neumann Boundary Conditions ). Sine would be wrong (its slope is non-zero at ends). So reuse Ex 2:
x = 2 π − π 4 ∑ k = 0 ∞ ( 2 k + 1 ) 2 c o s (( 2 k + 1 ) x ) .
Find the steady state. Why the a 0 /2 term? In Heat Equation — separation of variables , every cos ( n x ) mode decays to zero as time → ∞ ; only the constant 2 a 0 survives. An insulated rod conserves total heat , so it settles to the average temperature.
T ∞ = 2 a 0 = π 1 ∫ 0 π x d x = 2 π .
Verify by physics: total heat ∝ ∫ 0 π x d x = π 2 /2 ; spread uniformly over length π gives π π 2 /2 = 2 π . ✓ Matches. The cosine series' constant term is the steady state — a beautiful consistency.
Worked example Example 8 — the "which converges faster and to what" twist
Exam wording: "For f ( x ) = x on [ 0 , π ] , (i) state the large-n decay of the sine vs cosine coefficients, (ii) find what each series converges to at x = π ."
Forecast: you've seen both series (Ex 1, 2) and their two mirrors in figure s01. Answer before reading on.
Decay rates. Why do they differ? Coefficient decay is set by the smoothness of the periodic extension (figure s01). Sine → odd extension = sawtooth with a jump → b n ∼ 1/ n . Cosine → even extension = ∣ x ∣ , continuous with a corner → a n ∼ 1/ n 2 . One extra order of smoothness buys one extra power of n in decay.
Sine series at x = π . Why not π ? Jump of the sawtooth from + π to − π ; midpoint = 0 . Check: every sin ( nπ ) = 0 , so the series literally sums to 0 . ✓
Cosine series at x = π — unpack the sign. Why π ? The even extension is continuous there (no jump), so the series must equal f ( π ) = π . Let us verify the arithmetic explicitly. The cosine series (Ex 2) is
x = 2 π − π 4 ∑ k = 0 ∞ ( 2 k + 1 ) 2 c o s (( 2 k + 1 ) x ) .
At x = π each term needs cos ( ( 2 k + 1 ) π ) . Why is this − 1 ? Because 2 k + 1 is odd , and cosine at an odd multiple of π is − 1 : cos ( ( 2 k + 1 ) π ) = ( − 1 ) 2 k + 1 = − 1 . So every term becomes ( 2 k + 1 ) 2 − 1 , and the minus in front flips it to + :
x x = π = 2 π − π 4 ∑ k = 0 ∞ ( 2 k + 1 ) 2 − 1 = 2 π + π 4 ∑ k = 0 ∞ ( 2 k + 1 ) 2 1 = 2 π + π 4 ⋅ 8 π 2 = 2 π + 2 π = π .
(We used ∑ k ≥ 0 ( 2 k + 1 ) 2 1 = 8 π 2 .) So the cosine series gives exactly π = f ( π ) . ✓
Verify: cosine endpoint value = π (shown above), sine endpoint = 0 (every sin ( nπ ) = 0 ). ✓
Take-away for exams: smoother extension → faster decay; at a jump the answer is the midpoint.
Recall Cover the answers and fire away
Which cell do you pick for an insulated rod, and why? ::: Cosine (Neumann, zero slope at ends).
A constant c has a trivial cosine series but a non-trivial sine series — why? ::: Even mirror of c is just c ; odd mirror is a square wave full of sine wiggles.
The sine series of x at x = π sums to what, and why? ::: 0 , the midpoint of the sawtooth jump (Dirichlet rule).
Which decays faster, b n of the sawtooth or a n of ∣ x ∣ , and why? ::: a n ∼ 1/ n 2 faster than b n ∼ 1/ n ; corner is smoother than a jump.
Same tent, sine vs cosine — which one carries a constant term, and what is it? ::: The cosine one; its a 0 /2 = 2 1 (the tent's average height).
Ends fixed at zero? → sine. Ends insulated / has an average? → cosine. Answer looks wrong at an endpoint? → it's the midpoint, not a mistake.