Application Center - Maplesoft

# Classroom Tips and Techniques: Teaching Fourier Series with Maple

You can switch back to the summary page by clicking here.

Classroom Tips and Techniques: Teaching Fourier Series with Maple

Robert J. Lopez
Emeritus Professor of Mathematics and Maple Fellow
Maplesoft

Initializations

 >

 >

Introduction

After arriving at Rose-Hulman Institute of Technology in 1985, and before the advent of Maple in the classroom in 1988, I taught Fourier series in differential equations twice in a pencil-and-paper environment. Vivid memories of how ineffective the lessons on Fourier series were still remain.  I remember homework papers with a scattering of integrals, mostly incorrectly evaluated, a sum sign or two, and a lot of confusion as to what a Fourier series was supposed to represent.

In the very first DE course taught with Maple I noticed a remarkable difference in the section on Fourier series.  Students would come to my office with some print-out in hand, and show me a computer-drawn graph of a function and a partial sum of its Fourier series.  The two curves did not agree, so the question I'd be asked was "From the discrepancy in the two graphs, can you help me determine what error I made in the calculation of the series?"  I was amazed.  We had progressed from meaningless scribbles on paper to real insight into the behavior of the Fourier series.  You can be sure this experience provided strong support for my conviction that a tool like Maple was essential for teaching, learning, and doing mathematics at the dawn of the 21 century.

In this month's column, we begin an examination of four different Maple packages that users have written to simplify the calculation and exploration of the Fourier series.  The earliest such package, presently available from the Maple Application Center (www.mapleapps.com) was written by Wilhelm Werner, and came to my attention in 1998.  It was recently revised and re-submitted to the Application Center.  A second package by Amir Khanshan was first described in the Proceedings of the July 2006 Maple Conference, Waterloo, Ontario, Canada.  A third package, also available on the Application Center, is due to Napasin Sonjampa, a student at King Mongkut's Institute of Technology North Bangkok.  The fourth and most recent package,  announced on the MaplePrimes site (www.mapleprimes.com) August 21, 2006, is by Karel Srot.

Before exploring the functionalities provided by these packages, this month's column will show how the Fourier series can be computed and studied with just the tools in Maple itself.  This will set the background against which the "value-added" of any of these packages can be assessed.  The following formulas fix notation for the Fourier series of suitably restricted functions defined on an interval of length

In addition to fixing notation, let's also fix our terminology.  The general trigonometric series containing both sine and cosine terms will be called the sine-cosine series, while the series that contains just sine (or cosine) terms will be called the sine (or cosine) series, respectively.  The series whose coefficients are will be called the exponential series.  In light of the Euler formulas the coefficients of the exponential and sine-cosine series are related by and

Finally, we note that on the interval , a function can have any number of Fourier representations.  First, there are the sine and cosine series representations, depending on how the function is extended to , odd in the first case, even in the second.  Moreover, each non-symmetric extension to results in a different sine-cosine series, as does taking and

Columns in succeeding months will address the user-contributed packages at length.

Fourier Series in Maple

Assumptions could not be applied to Maple variables in 1988.  This feature did not arrive until the early 1990s when the assume command became available.  Without the assumption that the series index is an integer, Maple's expressions for Fourier coefficients, computed by direct integration, will generally contain terms like and the first of which should simplify to 0, and the second, to .  But the assume command has continuing after-effects, often to the confusion of the user, as we show with Example 1.  In Example 2, we explore what happens in Maple when the generic coefficient is produced by an integration formula that has inherent restrictions on its applicability.  In Example 3, we explore the periodic extension of and the convergence of a Fourier series to and to its periodic extension.  In Example 4, we obtain a Fourier sine series and draw a bar graph of the coefficients , calling this the spectrum of frequencies determined by this series.  In Example 5, we compare the exponential series with the sine-cosine series.

 Example 1 Obtain a Fourier sine-cosine series for .  Compare functionality of assume and assuming commands Example 2 Obtain a Fourier sine series for , a series for which the generic coefficient is undefined for a specific value of the index. Example 3 Obtain the Fourier series for and graph a partial sum on .  Compare the function, the Fourier series, and the periodic extension of the function. Example 4 Obtain the Fourier sine series for and graph its spectrum of frequencies. Example 5 Compare exponential and sine-cosine series for Table 1  Summary of examples implemented in Maple

Example 1

Begin with the assumption

 >

and the definitions

 >

 (3.1.1)

Then write the following integrals for the coefficients.

 >

 (3.1.2)

There are three immediate advantages to this approach.  First, the formulas for the coefficients are typed in exactly as they might appear in a text, minimizing the chance for errors and confusion.  Second, writing the inert form of the integrals gives the user a chance to notice (or find) data-entry errors.  Third, these formulas can be "reused" by a copy/paste operation and a redefinition of just and

Evaluating these integrals leads to the coefficients

 >

 (3.1.3)

and hence to partial sums of the form

 >

 (3.1.4)

The deleterious effect of the assume command is now seen when, for example, we generate a sequence of the first few coefficients

 >

 (3.1.5)

The assume command attached its assumptions to the variable , which then became a variable distinct from the used in the seq command, and not directly addressable from the keyboard.  Everything containing that was typed as input to Maple after the assumption was made is "contaminated" with  Removing the assumption from with

 >

does not change to in the expressions for the integrals or the coefficients, as we see from

 >

 (3.1.6)

Although the tendency for the tilde (~) to look like a minus sign can be overcome by a setting in the Tools/Options dialog, or even with an interface option entered from the keyboard, the inherent distinction between and remains exceedingly problematic for students, with relief available only with the assuming command that appeared in the late 1990s.

Let us show how the Fourier series can be computed in Maple without having to invoke the assume command.  Recall, we have removed the assumption on , but need to re-enter all other expressions containing it.  The integrals defining the coefficients are

 >

 (3.1.7)

and their values are

 >

 (3.1.8)

Alternatively, we could have used the syntax

 >

 (3.1.9)

but the assuming command proves to be much more useful in a wide spectrum of Maple calculations.

The first few 's are then

 >

 (3.1.10)

and the first 50 partial sums of the Fourier series are generated by the loop

 >

where we have suppressed what turns out to be a large output.  Figure 1 displays these partial sums via an animation.

 >

Figure 1   Convergence of first 50 partial sums to

And yes, we deliberately avoided the complication of defining the zeroth partial sum to be by adjoining this constant term to each of the first 50 partial sums containing trig functions.

Example 2

Using the revised formalism detailed in Example 1, we obtain a sine series for

 >

 (3.2.1)

on where

 >

 (3.2.2)

by writing

 >

 (3.2.3)

and computing

 >

 (3.2.4)

The experienced eye can see that is not defined by this expression.  Typically, students do not realize this, and proceed to write

 >

 Error, (in NumericRange) summand is singular in the interval of summation

for a partial sum, and are perplexed by the error message so generated.  Of course, the correct procedure is to write the separate integral

 >

 (3.2.5)

with value

 >

 (3.2.6)

Then, a partial sum of the sine series is obtained with syntax such as

 >

 (3.2.7)

That this partial sum approximates faithfully is demonstrated in Figure 2 where is in black, the partial sum is in red.

 >

 Figure 2 In black, the graph of in red, the graph of a partial sum of the Fourier sine series for

Example 3

The periodic extension of a function whose rule is and whose domain is is the periodic function of period , with rule and domain where is the greatest integer function.

This definition can be implemented in Maple by using floor as the greatest integer function.  For example, let with domain  If we write

 >

 (3.3.1)

the rule for becomes

 >

 (3.3.2)

because  Figure 3 verifies that reproduces periodically.

 >

Figure 3   In black, ; in red, its periodic extension

Denote the Fourier series of by .  (The function has rule and domain )  If is suitably continuous, and then the periodic extension of .  Thus, under the right conditions, the Fourier series represents on its domain, and outside its domain represents the periodic extension of

Indeed, the Fourier series for reduces to a cosine series because is an even function.  The coefficients are defined by the integrals

 >

 (3.3.3)

whose values are

 >

 (3.3.4)

A partial sum for this cosine series, namely,

 >

 (3.3.5)

is graphed in Figure 4.

 >

 Figure 4 For the Fourier cosine series the periodic extension of

If has jump discontinuous, or if then at each point its Fourier series converges to the average value of the limits from the left and right.  Since this is not easily shown with a partial sum, it is difficult to get Maple to demonstrate that at discontinuities the Fourier series converges to a point midway between the jump.

In any event, this means the statement "The Fourier series of converges to the periodic extension of " is not necessarily a true statement.  The periodic extension of will reproduce any jump discontinuities but the Fourier series will converge to a point midway between any jump.  Therefore, in general, the difference being the behavior at any jump discontinuities.

Example 4

The Fourier sine series for is easily obtained if we write

 >

 (3.4.1)
and the integral

 >

 (3.4.2)

whose value is

 >

 (3.4.3)

Figure 5 then contains a bar graph of the coefficients plotted against .  As such, it is a representation of the spectrum of frequencies in the sine series for a visual representation of the coefficients that multiply each sinusoid in the Fourier series.

 >

Figure 5   Spectrum of frequencies in the sine series for

Example 5

If the rule for is given by

 >

 (3.5.1)

and the domain is the interval so that , obtain its Fourier exponential series and compare the resulting to the coefficients of its Fourier sine-cosine series.  Figure 6 provides a graph of the function

 >

Figure 6   Graph of in Example 5

The coefficients are given by the integrals

 >

 (3.5.2)
whose values are

 >

 (3.5.3)

The coefficients in the sine-cosine series are given by the integrals

 >

 (3.5.4)

whose values are

 >

 (3.5.5)

To establish that , we interrogate Maple as follows.

 >

 (3.5.6)

A partial sum of the Fourier exponential series, and the corresponding partial sum of the sine-cosine series are given respectively by

 >

 (3.5.7)

That these two expressions are identical is shown by an application of Euler's formulas, implemented in Maple via

 >

 (3.5.8)

Legal Notice: The copyright for this application is owned by Maplesoft. The application is intended to demonstrate the use of Maple to solve a particular problem. It has been made available for product evaluation purposes only and may not be used in any other context without the express permission of Maplesoft.