# An Example of a Fourier Series # In this notebook, you will study the Fourier series of the 2*Pi;- periodic function which looks like f(x) = x; for `and`(0 < x, x < 2*Pi);. The graph of such a function is a sawtooth illustrated below. The first question that comes to mind is: How do we represent this function in Maple? # The formula that we give uses the floor# function, which is also called the greatest integer function in many books. # For more on this subject, see Section 2.1, Example 3 and Exercises 19--23. # Also, see the Mathematica Notebooks 2.2.periodic-func-1.nb and 2.2.periodic-func-2.nb. f:=x-> x-2*Pi*floor(x/(2*Pi)); plot( f(x),x=-4*Pi..4*Pi); # To compute the Fourier coefficients, we need the formula for f(x); on the interval [0, 2*Pi]; and the Euler formulas # for the Fourier coefficients (Section 2.2). On the interval [0, 2*Pi];, we have f:=x->x; # Soafter reminding Maple that we intend n# to be an integer, we get assume('n',integer); a:=n->int(f(x)*cos(n*x),x=0..2*Pi)/Pi; a(0):=int(f(x),x=0..2*Pi)/(2*Pi); b:=n->int(f(x)*sin(n*x),x=0..2*Pi)/Pi; a(n); b(n); # The partial sums of the Fourier series are S:=(n, x)->a(0) + sum(a(k)*cos(k*x) + b(k)*sin(k*x),k=1..n); # For example, we can try the 4th partial sum. S(4,x); # Note that there are no cosine terms, since all the a(n)'s are 0 for n=1, 2, ... Our next step is to compare the # graph of the partial sum to the graph of the function itself and see how well the partial sums are approximating the # function. Let us redefine f(x) so that we can see the repetitions over several periods. f:=x-> x - 2*Pi*floor(x/(2*Pi)); # Here are the graphs of f(x) and the tenth partial sum over three periods. plot([f(x), S(10, x)],x=-3*Pi..3*Pi,color=[red,black]); # We have a pretty good approximation of the function by the partial sum of its Fourier series, except near the points of # discontinuity of the function, x = 0, -2*Pi, 2*Pi, -4*Pi, 4*Pi; etc. Near the points of discontinuity, the partial sums are overshooting # the graph of the function. This phenomenon is called the Gibbs phenomenon. You can learn more about in Section 2.2, # Exercises 21--24. See also the Maple Worksheet 2.2.fourier-ser-1.nb. There are several other ways to # illustrate the graphs of the partial sums. We will show some now. See the Mathematica Notebook 2.2.fourier-ser-1.nb # for more methods of plotting. The following method allows you to animate the graphs when you're done plotting. Let's # plot first. with(plots): animate({f(x),S(N,x)},x=-3*Pi..3*Pi,N=1..15,view=-1..7,numpoints=300); # When you animate the graphs, you should see the hums near the points of discontinuity move # toward the discontinties without diminishing in magnitude. This suggests that the humps will not # go away, or that the approximation will not improve near points of discontinuity, even if you increase the terms in your # partial sum. This is again a consequence of the Gibbs phenomenon and you can learn more about at the references given before. # To confirm this claim, let us compare the graph of f(x) with the graph of the 100th partial sum. plot([f(x),S(100,x)],x=-3*Pi..3*Pi,color=[red,black],numpoints=400); #