Week 10

Fourier Series

In this week, we are beginning to explore the ability to express any periodic function (either periodic in space, or periodic in time) as a summation over an infinite number of Sin and Cos functions.  This is somewhat like expressing a 3-dimensional vector in terms of its x,y, and z components.  In this notebook, we will explore the notion of a Fourier series.  For this notebook, we will focus on functions f[x] that are periodic with period 2L, and that have boundary conditions where the function is vanishing at both x=0 and x=L.

Recall that we started from normal modes on a string that is fixed at x = 0 and x = L, and we imagined a string displaced from equilibrium, and then we took a snapshot at time t= 0.  If the configuration at that time (Subscript[t, 0])is described by the function f(x), then since all motion of the string near equilibrium can be expressed as a sum over the normal modes of oscillation, we have:

f(x) = (∑_(  ))An Cos[ (Subscript[ω, n])(Subscript[t, 0])+ (Subscript[α, n])] Sin[ n π/L x ] = ∑ Bn Sin[ n π/L x]

For a given shape of the string, f(x), we would like to be able to get the B’s, and vice versa.

In this notebook we will explore this formula.  First lets construct a shape with a set of B’s:

B[n_]=2 k L/n/π (-1)^(n+1);

At the moment, these values of B are the INPUT - later in this notebook, we will find the B’s corresponding to a particular function.

k=1;L=1;

Plot[{Sum[B[n]Sin[n π x/L],{n,1,3}],Sum[B[n]Sin[n π x/L],{n,1,10}],Sum[B[n]Sin[n π x/L],{n,1,100}],Sum[B[n]Sin[n π x/L],{n,1,1000}]},{x,0,L}]

It gives a “sawtooth” kind of graph - it looks like f(x) = x (and the approximation gets better as you include more sin functions).

Let’s look at the numerical values for these B’s:

Table[B[n],{n,1,10}]

Now let’s explore the reverse process, going from a function f(x) to the B’s:

First let’s show that Sin functions are “orthogonal” to each other, much like the basis vectors:

Clear[L]

ORTH[n_,m_]:=Integrate[2/L Sin[n π x/L] Sin[m π x/L],{x,0,L}];

MatrixForm[Table[ORTH[n,m],{n,1,10},{m,1,10}]]

We see that the integral is 1 when n=m, but zero otherwise!  This is like xhat * xhat = 1, and xhat*yhat = xhat*zhat = 0 in the case of basis vectors.  Now remember that to get the x component of a vector v, we dot v into x:  v_x = xhat*v.  In the case of Fourier series with the boundary conditions we are studying here, we have basis functions given by Similarly, to get the various components of the function f(x), we “dot” the basis functions into f(x):

L=1;

Let us *start* with the sawtooth, which is just a line starting at the origin with slope k:

f[x_]=k x;

Now we look at the integral of this f[x] with the basis functions Sin[n π x/L]:

INTsaw[n_]:=Integrate[2/L f[x] Sin[n π x/L],{x,0,L}]

Table[INT[n],{n,1,10}]

These are the same as the Bn’s above!

Now let us do a different function - a square wave.  In this case, g[x] is just a constant:

g[x_]=a;

Clear[L]

INTsquare[n_]:=Integrate[2/L g[x] Sin[n π x/L],{x,0,L}]

Table[INTsquare[n],{n,1,10}]

Looks like the Bn’s are 4a/n/π when n is odd, and zero otherwise.

Bsqr[n_]:=4 a/n/π * Boole[OddQ[n]];

Make a table to see if this works:

Table[Bsqr[n],{n,1,10}]

And it does, so now lets make a plot of the function using these B’s:

a=1;L=1;

Plot[{Sum[Bsqr[n] Sin[n π x/L],{n,1,2}],Sum[Bsqr[n] Sin[n π x/L],{n,1,10}],Sum[Bsqr[n] Sin[n π x/L],{n,1,1000}]},{x,0,L},PlotRange->{0,2}]

We see that the plot looks more and more like a square wave as we go higher and higher in the summation!

ORTHBC[n_,m_]:=Integrate[2/L Sin[2 π x(2n+1)/4/L]Sin[2 π x(2m+1)/4/L],{x,0,L}]

MatrixForm[Table[ORTHBC[n,m],{n,1,10},{m,1,10}]]