Physics Library
 An open source physics library
Encyclopedia | Forums | Docs | Random  

[parent] Fourier Cosine-Coefficient Derivation and Projection Exercises

(Example)

FS04E1: Fourier Cosine-Coefficient Derivation and Projection Exercises

FS04 derived the cosine coefficient formula

      1 ∫ π
am =  --    f(x)cos(mx  )dx,     m ≥  1,
      π  −π
(1)

and the constant coefficient

       ∫  π
a  = -1    f (x)dx.
 0   π   −π
(2)

This companion is calculation practice for those results. The emphasis is not on memorizing Equation (1). The emphasis is on repeatedly seeing why it is a projection formula, when symmetry can shorten the integral, how the constant term differs from the nonzero harmonics, and how integration by parts produces useful coefficient formulas.

The sine coefficient formula is deliberately not derived here. That belongs to FS05.

PIC

Figure 1. The exercise sequence moves from direct harmonic isolation to the DC coefficient, projection geometry, parity shortcuts, integration by parts, piecewise even functions, and finally the general interval [−L,L].

1 Three reusable checks

Cosine-coefficient extraction check

A cosine-coefficient extraction check verifies that multiplying a finite trigonometric sum by cos(mx) and integrating over [−π,π] leaves only the mth cosine term multiplied by its norm squared π.

DC-coefficient check

A DC-coefficient check verifies the distinction

      1∫  π
a0 = --    f (x)dx,
     π   −π
(3)

versus the actual constant term in the Fourier series,

        ∫ π
a0=  -1-    f(x )dx.
2    2π  − π
(4)

Thus a0∕2 is the mean value of f over the interval.

Cosine-projection residual check

After projecting f onto a cosine harmonic,

Pm (x) = am cos(mx ),
(5)

define the residual

rm (x) = f(x ) − Pm (x).
(6)

A correct projection satisfies

⟨rm, cos(mx )⟩ = 0.
(7)

PIC

Figure 2. Harmonic isolation acts like a filter. Multiplication by the target cosine and integration over a complete period removes the constant term, all sine terms, and all cosine harmonics with the wrong index.

2 Problems

All problems are stated before the hints and complete solutions.

Problem 1: isolate one known cosine coefficient

Let

f(x) = 4 + 3cos x − 2sin 2x + 7cos 3x.
(8)

Evaluate

  ∫ π
1-    f(x )cos3x dx
π  − π
(9)

by expanding every term. Do not simply read the answer from f(x).

Problem 2: rebuild the general extraction formula

Assume

              N
        a0-  ∑
f (x ) = 2  +     [an cos(nx) + bnsin(nx )].
             n=1
(10)

Multiply by cos(mx), integrate over [−π,π], and derive Equation (1) for 1 ≤ m ≤ N.

Problem 3: extract the constant coefficient from a finite sum

For

f(x) = 6 + 2cos x − 5sin 3x + 4cos 4x,
(11)

compute a0 by integration and identify the actual DC component a0∕2.

Problem 4: projection formula versus Fourier formula

Using the FS02 projection formula

     ⟨f,ϕ⟩-
c =  ⟨ϕ, ϕ⟩,
(12)

set

ϕ(x) = cos(mx )
(13)

on [−π,π] and derive the Fourier cosine coefficient formula directly.

Problem 5: residual orthogonality

Let

f(x) = x2,
(14)

and suppose that

a1 = − 4.
(15)

Define

P (x) = − 4 cosx,     r (x ) = x2 + 4cosx.
 1                     1
(16)

Verify directly that

∫
  π
    r1(x)cos xdx =  0.
 −π
(17)

Problem 6: even-function shortcut

Suppose f is even. Show that

      2 ∫ π
an =  --   f (x)cos(nx )dx.
      π  0
(18)

Explain why the shortcut works.

Problem 7: odd functions have zero cosine coefficients

Suppose f is odd. Show, without using the sine coefficient formula, that

an =  0
(19)

for every n ≥ 0.

Problem 8: the DC coefficient of x2

For

         2
f(x) = x ,     − π ≤ x ≤ π,
(20)

compute a0 and the mean value a0∕2.

Problem 9: cosine coefficients of x2

Starting from

        ∫
      2-  π  2
an =  π     x cos(nx )dx,
         0
(21)

perform integration by parts twice and derive

      4(− 1)n
an =  ---2---.
        n
(22)

Show every boundary term.

Problem 10: first cosine projection of x2

Using Problems 8 and 9, write the constant-plus-first-cosine approximation

S (c1)(x) = a0-+ a1 cosx.
           2
(23)

Evaluate it at x = 0 and x = π and compare with x2.

Problem 11: cosine coefficients of |x|

For

f(x) = |x|,    − π ≤ x ≤  π,
(24)

compute a0 and derive an by integration by parts. Simplify the result separately for even and odd n.

Problem 12: centered rectangular pulse

Let

       {
f(x) =   1,  |x| < π∕2,
         0,  π∕2 <  |x | ≤ π.
(25)

Compute a0 and an. Evaluate a1,a2,a3,a4,a5.

Problem 13: centered pulse of arbitrary half-width

Generalize Problem 12 to

       {
         A,   |x | < α,
f(x) =                         0 < α < π.
         0,   α < |x| ≤ π,
(26)

Derive a0 and an in terms of A and α.

Problem 14: triangular even function

Let

f(x) = π − |x|,    − π ≤ x ≤  π.
(27)

Compute a0 and derive the cosine coefficients. Identify which harmonics vanish.

Problem 15: general interval [−L,L]

For the basis

   ( nπx-)
cos   L    ,
(28)

use the projection formula to derive

      1 ∫ L         (n πx )
an = --     f(x)cos  ----  dx,     n ≥  1.
     L   −L            L
(29)

Also derive the corresponding a0 formula.

Problem 16: normalized-basis coefficient

Define

^ϕn (x ) = cos√(nx).
             π
(30)

If

c =  ⟨f, ^ϕ ⟩,
 n       n
(31)

show that

     √ --
cn =   π an.
(32)

Explain why cn and an are different numbers even though they describe the same projected function.

3 Hints

  1. Expand the four terms and use the FS03 orthogonality relations one at a time.
  2. Keep the sum finite. The cosine-cosine integral is π only when n = m.
  3. Every nonconstant integer sine or cosine integrates to zero over [−π,π].
  4. Compute ⟨cos(mx), cos(mx)⟩ explicitly.
  5. Use ∫ x2 cos xdx from the n = 1 case of Problem 9, or derive it directly twice by parts.
  6. The product of two even functions is even.
  7. Odd times even is odd.
  8. Use evenness before integrating.
  9. First choose u = x2 and dv = cos(nx)dx; then integrate the remaining x sin(nx) term by parts.
  10. From Problem 9, a1 = −4.
  11. |x| is even, so work only on [0,π].
  12. Only the interval [−π∕2,π∕2] contributes.
  13. Replace π∕2 by α and include amplitude A.
  14. Write π −|x| as π − x on [0,π].
  15. The norm squared of each nonzero cosine basis function on [−L,L] is L.
  16. The normalized basis has norm one, so its coordinate is the inner product itself.

4 Worked solutions

Solution 1: isolate one known cosine coefficient

Begin with

I = 1
--
π∫ −ππ(4 + 3 cosx − 2 sin 2x + 7 cos3x) cos 3xdx (33)
= 1-
π[  ∫ π              ∫ π

 4  −π cos3x dx + 3  −π cosx cos3x dx (34)
   ∫  π                   ∫ π           ]
− 2    sin2x cos 3xdx +  7    cos23x dx
     −π                    − π. (35)

The first three integrals are zero by orthogonality. The final integral is

∫  π
    cos2 3xdx =  π.
  −π
(36)

Therefore

     1
I =  π(7π) = 7.
(37)

The operation has isolated the coefficient of cos 3x.

Solution 2: rebuild the general extraction formula

Multiply the finite expansion by cos(mx):

f(x) cos(mx) = a0
---
2 cos(mx) (38)
+ ∑ n=1Na n cos(nx) cos(mx) (39)
+ ∑ n=1Nb n sin(nx) cos(mx). (40)

Integrate over [−π,π]:

∫ −ππf(x) cos(mx) dx = a
--0
 2 ∫ −ππ cos(mx) dx (41)
+ ∑ n=1Na n ∫ −ππ cos(nx) cos(mx) dx (42)
+ ∑ n=1Nb n ∫ −ππ sin(nx) cos(mx) dx. (43)

The constant-cosine integral vanishes. Every sine-cosine integral vanishes. Every cosine-cosine integral with n≠m vanishes. Only the n = m term remains:

∫ π
    f(x) cos(mx )dx =  amπ.
 − π
(44)

Divide by π:

       ∫  π
a  =  1-   f (x)cos(mx ) dx.
 m    π  −π
(45)

PIC

Figure 3. The constant basis function has norm squared 2π, so its projection coefficient is the mean value a0∕2. The Fourier symbol a0 is twice that mean.

Solution 3: extract the constant coefficient

Integrate the function:

∫ −ππf(x) dx = ∫ −ππ(6 + 2 cosx − 5sin 3x + 4cos 4x) dx (46)
= 12π. (47)

Therefore

     1
a0 = -(12 π) = 12.
     π
(48)

The actual constant term is

a0-=  6.
 2
(49)

That agrees with the constant visible in the original finite sum.

Solution 4: projection formula versus Fourier formula

Set

ϕ(x) = cos(mx ).
(50)

The projection coefficient is

     ⟨f,ϕ⟩
c =  ⟨ϕ,-ϕ⟩.
(51)

The numerator is

         ∫ π
⟨f,ϕ ⟩ =     f(x)cos(mx  )dx.
          −π
(52)

The denominator is

         ∫ π
               2
⟨ϕ,ϕ ⟩ =  −π cos (mx ) dx = π.
(53)

Therefore

       ∫ π
c =  1-    f(x)cos(mx ) dx.
     π  −π
(54)

Thus c = am.

PIC

Figure 4. The projection coefficient is chosen so that the residual has zero inner product with the target basis function. Fourier cosine extraction is this same geometric construction in function space.

Solution 5: residual orthogonality

We must evaluate

∫ π
    (x2 + 4cos x)cos xdx.
 −π
(55)

Split the integral:

∫                 ∫
  π  2               π   2
    x  cosx dx + 4    cos  xdx.
 − π                −π
(56)

The second integral is

4π.
(57)

For the first integral, evenness gives

∫ π                ∫ π
    x2 cosx dx = 2    x2 cosx dx.
 − π                0
(58)

Integrate by parts twice:

∫ 0πx2 cos xdx = [       ]
 x2 sin x 0π − 2 ∫ 0πx sin xdx (59)
= −2(              ∫ π        )
           π
  [− x cosx ]0 + 0  cosx dx (60)
= −2π. (61)

Hence

∫ π
    x2cos xdx =  − 4 π.
 −π
(62)

Therefore the residual inner product is

− 4π +  4π = 0.
(63)

Solution 6: even-function shortcut

If f is even, then cos(nx) is also even. Their product is even:

f(− x)cos(− nx ) = f(x)cos(nx ).
(64)

Therefore

∫  π                    ∫ π
    f (x )cos(nx) dx = 2    f (x)cos(nx )dx.
  −π                     0
(65)

Substitute into the coefficient formula:

        ∫
      2   π
an =  --   f (x)cos(nx )dx.
      π  0
(66)

Solution 7: odd functions have zero cosine coefficients

If f is odd and cos(nx) is even, then

f(x)cos(nx )
(67)

is odd. Hence

∫ π
    f(x )cos(nx) dx = 0
 − π
(68)

for n ≥ 1, so

an = 0.
(69)

For n = 0 the integrand is simply f(x), which is odd, so

a0 = 0.
(70)

PIC

Figure 5. Parity can replace half of the integration work. Even functions reinforce across the symmetric interval, while an odd target function multiplied by an even cosine cancels exactly.

Solution 8: the DC coefficient of x2

Because x2 is even,

a0 = 2-
π∫ 0πx2 dx (71)
= 2
--
π[x3 ]
 ---
  30π (72)
= 2π2
----
 3. (73)

Therefore the mean value is

a0-   π2-
 2 =   3 .
(74)

Solution 9: cosine coefficients of x2

Start with

      2 ∫ π
an =  --    x2cos(nx )dx.
      π  0
(75)

Let

u = x2,     dv = cos(nx )dx.
(76)

Then

du =  2x dx,     v = sin-(nx).
                        n
(77)

Thus

∫ 0πx2 cos(nx) dx = [ 2        ]
 x--sin(nx-)
     n0π −-2
n∫ 0πx sin(nx) dx (78)
= −2
--
n∫ 0πx sin(nx) dx, (79)

because sin(nπ) = 0.

For the remaining integral, choose

u =  x,    dv =  sin(nx )dx,
(80)

so

                   cos(nx-)
du = dx,     v = −    n    .
(81)

Then

∫ 0πx sin(nx) dx = [           ]
   x-cos(nx)
 −     n0π + 1-
n∫ 0π cos(nx) dx (82)
= −π-cos(nπ-)
    n (83)
= −π (− 1 )n
--------
   n. (84)

Therefore

∫  π                       n
     2              2π(−-1)--
  0 x  cos(nx )dx =     n2   .
(85)

Finally,

      2 2π(− 1)n   4(− 1)n
an =  ------2----= ----2--.
      π    n          n
(86)

PIC

Figure 6. The x2 coefficient calculation requires two integrations by parts. The first removes one Power of x; the second converts the remaining integral into boundary terms containing cos(nπ) = (−1)n.

Solution 10: first cosine projection of x2

From Problems 8 and 9,

       2
a0-= π--,    a1 = − 4.
2     3
(87)

Therefore

 (c)     π2-
S1 (x) =  3 −  4cos x.
(88)

At x = 0,

 (c)     π2
S1 (0) = ---−  4 ≈ − 0.7101,
          3
(89)

whereas

f(0) = 0.
(90)

At x = π,

         π2
S(1c)(π) = ---+  4 ≈ 7.2899,
          3
(91)

while

f(π) = π2 ≈  9.8696.
(92)

One harmonic is only a low-order projection, so pointwise agreement is not expected to be exact.

Solution 11: cosine coefficients of |x|

Because |x| is even,

     2 ∫ π
a0 = --    xdx =  π.
     π  0
(93)

Thus

a0-= π-.
2     2
(94)

For n ≥ 1,

     2 ∫  π
an = --    x cos(nx)dx.
     π   0
(95)

Integrate by parts:

∫ 0πx cos(nx) dx = [ xsin(nx)]
  ---------
     n0π −1
--
n∫ 0π sin(nx) dx (96)
= (−-1)n −-1
    n2. (97)

Therefore

an = --2- [(− 1)n − 1].
     πn2
(98)

If n is even,

an = 0.
(99)

If n is odd,

       -4--
an = − πn2 .
(100)

Solution 12: centered rectangular pulse

The pulse is even. Its constant coefficient is

a0 =  2
--
π∫ 0π∕21 dx (101)
= 1. (102)

Thus its mean value is 1∕2.

For n ≥ 1,

an = 2
--
π∫ 0π∕2 cos(nx) dx (103)
= -2-
πn sin (    )
  nπ-
  2. (104)

Hence

a1 = 2
--
π, (105)
a2 = 0, (106)
a3 = − 2
3-π, (107)
a4 = 0, (108)
a5 = 2--
5π. (109)

PIC

Figure 7. The centered half-duty pulse has alternating nonzero odd cosine coefficients and vanishing even cosine coefficients. The pattern comes directly from sin(nπ∕2).

Solution 13: centered pulse of arbitrary half-width

Again use evenness. The constant coefficient is

a0 =  2
--
π∫ 0αAdx (110)
= 2A-α-
  π. (111)

Therefore the mean value is

a     Aα
-0-=  ---.
2     π
(112)

For n ≥ 1,

an = 2A
---
 π∫ 0α cos(nx) dx (113)
= 2A-
πn sin(nα). (114)

Problem 12 follows by setting

               π
A = 1,     α = --.
                2
(115)

Solution 14: triangular even function

On [0,π],

f(x) = π − x.
(116)

The constant coefficient is

a0 = 2-
π∫ 0π(π − x)dx (117)
= π. (118)

Hence the mean is π∕2.

For n ≥ 1,

an = -2
π∫ 0π(π − x) cos(nx)dx. (119)

The π cos(nx) term integrates to zero, so

         ∫  π
an = − 2-    x cos(nx)dx.
       π   0
(120)

From Problem 11,

∫ π                    n
                   (−-1)--−-1-
 0  x cos(nx )dx =     n2    .
(121)

Thus

       2           n
an = ---2 [1 − (− 1) ].
     πn
(122)

For even n,

an = 0.
(123)

For odd n,

      4
an = ---2.
     πn
(124)

Solution 15: general interval [−L,L]

Take

           (     )
ϕn(x) = cos  nπx-  .
              L
(125)

The projection formula gives

     -⟨f,ϕn⟩-
an = ⟨ϕn,ϕn ⟩.
(126)

FS03 gives

⟨ϕ  ,ϕ ⟩ = L
  n  n
(127)

for n ≥ 1. Therefore

      1 ∫ L         ( nπx )
an =  --    f(x )cos  ----  dx.
      L  − L           L
(128)

For the constant basis function,

⟨1,1⟩ = 2L.
(129)

The actual constant projection is therefore

 1  ∫ L
---     f(x)dx.
2L   −L
(130)

Since the Fourier convention writes this constant as a0∕2,

        ∫
     -1   L
a0 = L      f(x)dx.
         −L
(131)

Solution 16: normalized-basis coefficient

The normalized cosine basis function is

         cos(nx)
^ϕn (x ) = --√-π--.
(132)

Its coordinate is

cn = ⟨   ^ ⟩
 f, ϕn (133)
=  1
√---
  π∫ −ππf(x) cos(nx)dx. (134)

But

∫ π
    f(x)cos(nx )dx = πan.
 −π
(135)

Therefore

     √ --
cn =   π an.
(136)

The two numerical coefficients differ because they multiply differently scaled basis functions:

an cos(nx) = (√ π-an)cos√(nx-)-
   π (137)
= cnϕn(x). (138)

The projected function is the same.

5 Additional practice

  1. For f(x) = 2−3 cos 2x+8 sin 5x+6 cos 6x, isolate the coefficient of cos 6x by integration.
  2. Compute a0 for f(x) = 5 + cos 7x − 4 sin 2x.
  3. Show directly that all cosine coefficients of f(x) = x3 vanish on [−π,π].
  4. Compute a0 and a1 for f(x) = 1 + x2.
  5. Compute a2 and a3 for f(x) = x2 using the closed formula from Problem 9.
  6. For f(x) = |x|, evaluate a1,a2,a3,a4.
  7. For a centered pulse with A = 3 and α = π∕3, compute a0,a1,a2,a3.
  8. For f(x) = π −|x|, write the constant plus first three nonzero cosine terms.
  9. On [−2, 2], derive the coefficient multiplying cos(nπx∕2).
  10. Explain why replacing cos(nx) by 5 cos(nx) changes the projection coefficient but not the projected function.

6 What these exercises establish

The main lessons are:

  • A Fourier cosine coefficient is an ordinary function-space projection coefficient.
  • Orthogonality performs the harmonic isolation.
  • The factor 1∕π is the reciprocal norm squared of cos(nx) on [−π,π].
  • The quantity a0∕2, not a0, is the mean or DC component.
  • Evenness can reduce symmetric-interval integrals to twice a half-interval integral.
  • Odd functions have no constant or cosine content on a symmetric interval.
  • Integration by parts converts polynomial-times-cosine integrals into boundary terms that reveal coefficient decay and sign patterns.
  • Piecewise even functions often produce transparent spectral selection rules such as vanishing even harmonics.

PIC

Figure 8. FS04E1 completes the cosine side of coefficient extraction. FS05 will apply the same projection logic to sine harmonics and place the cosine, sine, and constant coefficients into one unified Fourier-series formula.

References

[1]   PhysicsLibrary, FS04: Derivation of the Fourier Cosine Coefficients.

[2]   PhysicsLibrary, FS03: Orthogonality of Sines and Cosines.

[3]   R. V. Churchill and J. W. Brown, Fourier Series and Boundary Value Problems, McGraw-Hill.

[4]   E. Kreyszig, Advanced Engineering Mathematics, Wiley.


"Fourier Cosine-Coefficient Derivation and Projection Exercises" is owned by bloftin.
(view preamble)
View style:
Other names:  FS04E1
Keywords:  Fourier series, cosine coefficient, Fourier coefficient, projection, orthogonality, DC component, mean value, integration by parts, even function, piecewise function

This object's parent.

Cross-references: Power, projection coefficient, operation, inner product, amplitude, relations, FS03, boundary, works, Fourier cosine coefficient, FS02, DC component, period, Fourier series, norm, functions, parity, FS05, harmonics, formula, FS04
There is 1 reference to this object.

This is version 1 of Fourier Cosine-Coefficient Derivation and Projection Exercises, born on 2026-10-27.
Object id is 1538, canonical name is FourierCosineCoefficientDerivationAndProjectionExercises.
Accessed 8 times total.

Classification:
Physics Classification: 02.30.Nw (Fourier analysis)
 02.30.Lt (Sequences, series, and summability)

Pending Errata and Addenda

None.

Discussion

No messages.

Interact