\magnification = \magstep1
\centerline{Mathematics 373 -- Applied Mathematics (PDE)}
\centerline{Lab/Demonstration 1 -- Fourier Series}
\centerline{February 22, 2001}
\bigskip
\noindent
{\it Background}
\bigskip
On Tuesday, we introduced the Fourier series of a function $f(x)$ on 
$[-L, L]$:
$$a_0/2 + \sum_{n=1}^\infty \left( a_n \cos\left({n\pi x\over L}\right) +
b_n \sin\left({n\pi x\over L}\right) \right)\leqno(1)$$
where:
$$\cases{
a_n = {1\over L} \int_{-L}^L f(x) \cos\left({n\pi x\over L}\right)\ dx & if $n \ge 0$\cr
b_n = {1\over L} \int_{-L}^L f(x) \sin\left({n\pi x\over L}\right)\ dx & for $n \ge 1$\cr}$$

In this lab, you will compute Fourier series for several functions 
using Maple, plot partial sums of the Fourier series together with the 
function, and observe some patterns.  Because you will be working on the 
Midterm Problem Set this coming week, I will not ask you to turn in
an assignment
based on this lab.  However some of the Midterm problems will involve
using Maple in ways similar to what you do today.  So you will
want to generate a commented worksheet based on the examples below
for your own reference.  There is a worksheet with additional
examples on the course homepage.

\bigskip
\noindent
{\it Lab Activities}
\bigskip
\noindent
I.  A First Example -- {\it the ``sawtooth function'' -- the reason for
the name will become clear in part B below}.  
Let $f(x) = x$ on $[-1,1]$ ($L = 1$).  This is clearly piecewise
continuous! The Fourier coefficients can be computed in Maple as follows.
First enter the command 
\medskip
\centerline{\tt assume(n,integer);}
\medskip
\noindent
Then as in the handout from class on Tuesday, we can define functions 
$a$ and $b$ that return the values of the Fourier coefficients as formulas 
in $n$:
\medskip
\centerline{\tt a := n -> int(x*cos(n*Pi*x),x=-1..1);}
\centerline{\tt b := n -> int(x*sin(n*Pi*x),x=-1..1);}
\medskip
\noindent
Enter these definitions.  You can see the formulas for the Fourier coefficients
by entering commands
\medskip
\centerline{\tt a(n); b(n);}
\medskip
\noindent
One batch of these is always zero.  Explain how we could have known
this.

\bigskip
Next, we can define a function that will compute a given partial sum 
$$a_0/2 + \sum_{n=1}^N \left( a_n \cos(n\pi x) +
b_n \sin(n\pi x) \right)$$
of the Fourier series for our function:
\medskip
\centerline{\tt PSFS := (N,x) -> a(0)/2 + sum(a(n)*cos(n*Pi*x)+b(n)*sin(n*Pi*x),n=1..N);}
\medskip
\noindent
Note, this uses the general formula (1) given above.  In cases
like the one we are working with here, where one set of coefficients
is automatically zero, we could also leave those terms out.
To plot the $N = 5$ partial sum together with $f$ for $x \in [-1,1]$, use
\medskip
\centerline{\tt plot($\{$x,PSFS(5,x)$\}$,x=-1..1);}
\medskip
\noindent
\item{A)}  Increase $N$ to 10,15,20 and generate new plots of 
the corresponding partial sums of the Fourier series, together with $f$.  
What seems to be happening as $N$ increases?  Pay special 
attention to the partial sums near the endpoints of the interval ($x = -1,1$).
\item{B)}  Now plot the function $f$ together with the partial sum with
$N = 20$ on the larger interval $[-4,4]$.  Why must $f$ and the Fourier 
series be {\it different} on this larger interval?  
\item{C)} Take $N$ even larger if necessary, and describe the 
function to which the partial sums of the Fourier series seem to 
be converging on $[-4,4]$.
\item{D)}  What does the Fourier series appear to be doing at 
$x = \ldots, -3, -1, 1, 3, \ldots$
where the function obtained from $f$ by {\it repeating the 
portion of the graph in $[-1,1]$ in intervals of length 2} 
(called the ``periodic extension'' of $f$) has jump discontinuities?  
\bigskip
\noindent
II.   Investigate the partial sums of the 
Fourier series for $f(x) = \cos(x)$ on $[-1,1]$, and also on the 
larger interval $[-4,4]$.  Which features of this example are
similar to what you saw in I?  Which features are different?
\bigskip
\noindent
III.  Repeat question I for the function 
$$f(x) = \cases{e^{-x} & if $-1/2 \le x \le 1/2$\cr
                0 & if $|x| > 1/2$\cr}$$
You will need first to figure out how to compute the Fourier coefficients.
(The function $f$ can be defined using the {\tt piecewise}
command in Maple.  Look this up in the online help for more info.)  
What is happening at the points $-1/2, 1/2$, where
the function $f$ itself has jump discontinuities?
\bye

              