Fourier Series

There are lots of slightly different representations of a function f by a sum of trigonometric series.  All get called Fourier Series.  All are initially motivated by our separation of variables argument for PDEs.

Fourier Sine Series 0<x<L

Homogeneous Dirichlet-Dirichlet (ϕ[0]=ϕ[L]=0) conditions gave us a list of functions 
 	{Sin[π x/L], Sin[2 π x/L], …}
 The Fourier Sine Series is f~(∑_(k=1)^∞)b[k]Sin[k π x/L]  where
 	b[k]=(2/L)(∫_0^L)f[x] Sin[kπ x/L]dx.
 The series converges (with some wiggles) to the odd periodic extension of the original function f.

To see the formula for b[n] we assume the representation
	f[x]=(∑_(k=1)^∞)b[k]Sin[k π x/L]
multiply both sides by Sin[n π x/L] and integrate
	(∫_0^L)f[x]Sin[n π x/L] 𝕕x=(∑_(k=1)^∞)b[k](∫_0^L)Sin[k π x/L]Sin[n π x/L] 𝕕x
As we noted before the sin-sin integrals are zero unless k=n so we get
	(∫_0^L)f[x]Sin[n π x/L] 𝕕x=b[n](∫_0^L)Sin[n π x/L]Sin[n π x/L] 𝕕x
Computing the surviving the integral gives 
	(∫_0^L)f[x]Sin[n π x/L] 𝕕x=b[n] L/2
which is our recipe.

More Detail and Pics

A Fourier Sine Series for f[x] defined on an interval 0<x<L is defined by the constants b[1], b[2],…
	({{(∑_(k=1)^∞)b[k]Sin[k π x/L], =, f[x]}})
It turns out provided you are prepared to be slightly flexible about what the “=” means that you can write down a Fourier Sine series for almost any function most folks can imagine.

Pretend you have ({{(∑_(k=1)^∞)b[k]Sin[k π x/L], =, f[x]}}).

Multiply both sides by Sin[π x/L]

({{(∑_(k=1)^∞)b[k]Sin[k π x/L] Sin[π x/L], =, f[x]}})Sin[π x/L]

Integrate from 0<x<L.

({{(∑_(k=1)^∞)b[k](∫_0^L)Sin[k π x/L] Sin[π x/L]dx, =, (∫_0^L)f[x] Sin[π x/L]dx}})

The Sin*Sin integrals are computable and simple.

If k≠1 (∫_0^L)Sin[k π x/L] Sin[π x/L]dx=0

(∫_0^L)Sin[π x/L] Sin[π x/L]dx=L/2

Simplify and solve for b[1]

({{b[1], =, (2/L)(∫_0^L)f[x] Sin[π x/L]dx}})

Multiply both sides by Sin[2π x/L]

({{(∑_(k=1)^∞)b[k]Sin[k π x/L] Sin[2π x/L], =, f[x]}})Sin[2π x/L]

Integrate from 0<x<L.

({{(∑_(k=1)^∞)b[k](∫_0^L)Sin[k π x/L] Sin[2π x/L]dx, =, (∫_0^L)f[x] Sin[2π x/L]dx}})

The Sin*Sin integrals are computable and simple.

If k≠2 (∫_0^L)Sin[n π x/L] Sin[2π x/L]dx=0

(∫_0^L)Sin[2π x/L] Sin[2π x/L]dx=L/2

Simplify and solve for b[2]

({{b[2], =, (2/L)(∫_0^L)f[x] Sin[2π x/L]dx}})

Multiply both sides by Sin[3π x/L] …

What you wind up with is a simple formula
	b[n]=(2/L)(∫_0^L)f[x] Sin[nπ x/L]dx
Lets be carefull, we have shown that:

If f[x] has a Fourier Sine series; and
It is OK to switch the order of integration and summation; and
Everything converges then b[n] has to be given above.

L=3;
nMax=25;
f[x_]:=1+x + (x^2)
Do[
b[n]=(2/L)NIntegrate[Sin[n π x/L] f[x],{x,0, L}],
{n, 1,nMax}]
Manipulate[
Plot[ 
{f[x], Sum[b[n] Sin[n π x /L],{n,1, nn}]},
{x, -1.5 L, 1.5 L},
GridLinesStyle->{Red, Blue},
GridLines->{{-L,0,L},Automatic}
],
{{nn,4},Range[1,nMax]}]

Fourier Cosine Series 0<x<L

As we shall see, homogeneous Neumann-Neumann (ϕ'[0]=ϕ'[L]=0) conditions gave us a list of functions 
 	{1,Cos[π x/L], Cos[2 π x/L], …}
 The Fourier Cosine Series is f~(∑_(k=0)^∞)a[k]Cos[k π x/L]  where for k≠0
 	a[k]=(2/L)(∫_0^L)f[x] Cos[k π x/L]dx
 and 	a[0]=(1/L)(∫_0^L)f[x]dx
 The series converges (with some wiggles) to the even periodic extension of the original function f.

To see the formula for a[n] we assume the representation
	f[x]=(∑_(k=1)^∞)a[k]Cos[k π x/L]
multiply both sides by Cos[n π x/L] and integrate
	(∫_0^L)f[x]Cos[n π x/L] 𝕕x=(∑_(k=1)^∞)a[k](∫_0^L)Cos[k π x/L]Cos[n π x/L] 𝕕x
The cosine-cosine integrals are zero unless k=n so we get
	(∫_0^L)f[x]Cos[n π x/L] 𝕕x=a[n](∫_0^L)Cos[n π x/L]Cos[n π x/L] 𝕕x
Computing the surviving the integrals for n≠0 gives 
	(∫_0^L)f[x]Cos[n π x/L] 𝕕x=a[n] L/2
for n=0 we get
	(∫_0^L)f[x] 𝕕x=a[0] L
which gives our recipe.

Pics

L=5.3;
nMax=25;
f[x_]:=(E^x)Cos[x]+Sin[x]
Do[
a[n]=(2/L)NIntegrate[Cos[n π x/L] f[x],{x,0, L}],
{n, 1,nMax}];
a[0]=(1/L)NIntegrate[f[x],{x,0,L}];
Manipulate[
Plot[ 
{f[x], Sum[a[n] Cos[n π x /L],{n,0, nn}]},
{x, -1.5 L, 1.5 L},
GridLinesStyle->{Red, Blue},
GridLines->{{-L,0,L},Automatic}
],
{{nn,14},Range[1,nMax]}]

Fourier Series -L<x<L

Fourier Series are usefull outside of PDE and a general Fourier Series contains both sin and cos terms
	f=a[0]+ (∑_(k=1)^∞)(a[k]Cos[k π x/L]+b[k] Sin[k π x/L])
It converges to the periodic extension of f. You work out the recipe for the coefficients a[k] and b[k] using our favorite trick.

To see the formula for a[n] we assume the representation
	f=a[0]+ (∑_(k=1)^∞)(a[k]Cos[k π x/L]+b[k] Sin[k π x/L])
If you integrate from -L to L all the trig functions cancel
	(∫_(-L)^L)f[x]𝕕x=(∫_(-L)^L)a[0]𝕕x=2L a[0]
so a[0] is simply the  average of f i.e.
	a[0]=(0.5/L)(∫_(-L)^L)f[x]𝕕x

Multiply both sides by Cos[n π x/L] and integrate from -L to L.  As before any mismatched cosines cancel.  All sine cosine products cancel because they are odd functions integrated over an even interval.  What is left is
	a[n]=(((∫_(-L)^L)Cos[n π x/L]f[x]𝕕x)/((∫_(-L)^L)((Cos[n π x/L])^2)𝕕x))=(((∫_(-L)^L)Cos[n π x/L]f[x]𝕕x)/L)

Multiply both sides by Sin[n π x/L] and integrate from -L to L.  As before any mismatched sines cancel.  All sine cosine products cancel because they are odd functions integrated over an even interval.  What is left is
	b[n]=(((∫_(-L)^L)Sin[n π x/L]f[x]𝕕x)/((∫_(-L)^L)((Sin[n π x/L])^2)𝕕x))=(((∫_(-L)^L)Sin[n π x/L]f[x]𝕕x)/L)

Pics

L=2;
nMax=50;
f[x_]:=(E^(Sin[ 2 x]))
Do[
a[n]=(1/L)NIntegrate[Cos[n π x/L] f[x],{x,-L, L}];
b[n]=(1/L)NIntegrate[Sin[n π x/L] f[x],{x,-L, L}],
{n, 1,nMax}];
a[0]=(0.5/L)NIntegrate[f[x],{x,-L,L}];
Manipulate[
Plot[ 
{f[x], a[0]+Sum[(a[n] Cos[n π x /L]+b[n] Sin[n π x /L]),{n,1, nn}]},
{x, -1.5 L, 1.5 L},
GridLinesStyle->{Red, Blue},
GridLines->{{-L,0,L},Automatic}
],
{{nn,14},Range[1,nMax]}]