Classroom Tips and Techniques: Teaching Fourier Series with Maple - Part 3
Robert J. Lopez
Emeritus Professor of Mathematics and Maple Fellow
Maplesoft
Initializations
Once the files for the FourierSeries package by Wilhelm Werner are in place, the following command will load its code.
Introduction
In this third article in a series devoted to Maple implementations of Fourier series calculations, we describe the FourierSeries package provided to the Maple Application Center by Wilhelm Werner. In the first article of this series, we detailed how to implement the calculations for Fourier series using just commands built into Maple. In the second, we detailed the Fourier series package by Amir Khanshan.
The FourierSeries Package by Wilhelm Werner
Available from the Maple Application Center, the FourierSeries package by Wilhelm Werner provides the five commands in Table 1. We will show how these commands meet the syntactic challenges posed by the computation and graphing of Fourier series.
Command
Input
Output
FourierCoeff
function data, series type
coefficients as function of index
FourierExtend
function data, type of extension, direction of extension
odd or even extension as a function
FourierPlot
function data, series type, index value, plot interval
graph of function, and partial sum of series
FourierAnimate
animation of partial sums converging to function
FourierSpectrum
function data, index value
graph of vs. index
Table 1 Commands in the FourierSeries package by Wilhelm Werner
In addition, the global input parameter listed in Table 2 determines the nature of the output of the FourierCoeff command.
Parameter
Effect
_FourierSeriesShowFunction
control display of the function whose Fourier coefficients are being computed, including display of piecewise linear function created by FourierCoeff whose input is a list of points
Table 2 Effect of global input parameter on FourierCoeff command
The FourierSeries package, and instructions for installing it, can be found on the Maple Application Center. The code is too bulky to include in this worksheet, so experiments with the commands in the package require downloading and installing the package. We have suppressed the residue of our installation process, showing only the use of the commands themselves.
Parameters
Coefficients Returned
FourierReal
and for trigonometric sine-cosine series, displayed
FourierComplex (FourierExp)
for exponential series, as function of index
FourierCos
from the trigonometric sine-cosine series, as function of index
FourierSin
Table 3 Parameters accepted by the FourierCoeff command
Although it takes the four parameters listed in Table 3, the FourierCoeff command always computes the coefficients of the complex series. The parameter FourierReal causes FourierCoeff to display the coefficients of the trigonometric (sine-cosine) series, whereas the parameter FourierExp causes it to return, as a function of the index, the coefficients of the exponential form of the series.
The FourierCos and FourierSin options do not instruct the FourierCoeff command to create the cosine or sine series. Instead, they generate, as functions of the index , and , the coefficients of the cosine terms, and sine terms, respectively, of the sine-cosine series.
To display the Fourier sine-cosine coefficients for
on use the syntax
Note that the quotes on the parameter FourierReal are necessary.
The piecewise functions displayed as and are not assigned to these names. For example, trying to obtain with the syntax
shows no assignments have been made.
To obtain the coefficients as functions, separately generate and with
The coefficients and are now functions of the index , as we see from
Although the calls
produce the generic expressions generated by the int command, a partial sum of the associated Fourier series can be obtained with the syntax
Notice from the generic expressions for and that each expression is undefined for The add command in Maple evaluates and as per their definitions as piecewise functions of , and produces the appropriate partial sum. For and as created by the FourierCoeff command, the sum command (and its 2D counterpart from the Expression palette) behaves differently, and will not provide evaluation of either or as we see from
In the special case where is a piecewise linear function, it can be entered as a list of points. For example, the Fourier series coefficients for the piecewise linear function
defined on and whose graph appears in Figure 1,
Figure 1 Graph of piecewise linear function
are given by
With a setting of the global parameter
the FourierSeries command will now provide the piecewise representation of the list of points used to describe the piecewise linear function.
Unfortunately, there are no provisions for declaring the name of the independent variable, or for specifying a domain for the resulting . The echo of the function is suppressed with
The coefficients for the complex (or exponential) form of the Fourier series for are obtained with the syntax
A partial sum of the associated (exponential) Fourier series is
The trigonometric form is then
Since is an odd function, this is easily checked by computing
and hence,
With sufficient care, the FourierCoeff command can also be used to display the coefficients of a sine or cosine series. For example, to obtain the sine series of the function
whose domain is the interval write the odd extension of as
The alternative to the FourierExtend command would be
requiring Maple coding at a more fundamental level.
Figure 2 verifies that is indeed the odd extension of to the interval
Figure 2 The odd extension of to
The Fourier sine-cosine series will have and the coefficients will be the coefficients of the sine series. We can see this from
but the actual calculation we want to make is
By way of comparison, we can also obtain the by evaluating the integral
whose value is
which compares favorably with
The comparison can also be make by partitioning via
FourierPlot, FourierAnimate, and FourierSpectrum
The remaining three commands in the FourierSeries package generate graphs. When working outside the package, the standard approach is to generate the Fourier coefficients, then form a partial sum of the series, and finally, to draw an appropriate graph. Using the FourierPlot command, however, the graph of a partial sum is superimposed on a graph of the function without the user having to obtain either the coefficients or the partial sum. Thus, for the function
we obtain Figure 3.
Figure 3
Partial sum of Fourier sine-cosine series for superimposed on the periodic extension of the function
The partial sum graphed in Figure 3 can be obtained by writing
and then
Figure 4 provides proof that the parameter used in the FourierPlot command gives rise to the partial sum
Figure 4 Graph of the partial sum and
Figure 5 contains the animation provided by the FourierAnimate command, and shows how a sequence of partial sums converges to .
Figure 5 Animation showing convergence of partial sums
Finally, Figure 6 contains a graph of the frequency spectrum, a bar graph representing the points drawn by the FourierSpectrum command. (It is essential to add at least one plot option to this command.)
Figure 6 Frequency spectrum vs for
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.