Application Center - Maplesoft

App Preview:

Classroom Tips and Techniques: Teaching Fourier Series with Maple - Part 2

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

Learn about Maple
Download Application


 

Image 

Classroom Tips and Techniques: Teaching Fourier Series with Maple - Part 2 

 

Robert J. Lopez 

Emeritus Professor of Mathematics and Maple Fellow 

Maplesoft 

 

Introduction 

 

The first article in this series on Teaching Fourier Series with Maple described how to implement the relevant calculations and graphs directly in Maple.  Because these computations require a certain amount of Maple syntax, several faculty members have written dedicated packages that simplify using Maple for teaching and implementing Fourier series.  The most recent such package added to the Maple Application Center is the FourierSeries package by Amir Khanshan, announced at the 2006 Maple Conference in Waterloo, Ontario, Canada, and written up in its Proceedings (ISBN 1-897310-13-7).  Similar in functionality to the FourierSeries package by Wilhelm Werner (to be detailed in our next article), it does not, however, have a provision for creating the odd and even extensions of a function.  This is counterbalanced by the greater simplicity with which a partial sum of the trigonometric series can be obtained in the Khanshan package.  Graphs and animations are somewhat easier in Werner's package, but analytic representations of coefficients and partial sums are easier to obtain in Khanshan's package. 

 

The basic working command of Khanshan's package is the fs command, which computes Fourier coefficients as functions, for both the trigonometric and exponential forms of the series.   

 

In the trigonometric case, the command has the option of returning an additional function that generates partial sums.  The fs command writes the formal series by default, a setting that can be changed with the showfs variable.  The rept command draws the periodic extension of a function defined on a finite interval, and the decompose command modifies the representation of the Fourier coefficients. 

 

Unfortunately, there are no help pages in this package, but its functionality is well documented in an accompanying worksheet prepared by Professor Khanshan.  The package itself was initially made available to the author by Professor Khanshan, but is now available on the Maple Application Center (www.mapleapps.com).  The package code and instructions for installing it are available at the end of the link provided.  In this article, we will assume access to the package, but readers will have to install the package themselves if they want to reproduce the calculations given here. 

 

>  
 

The FourierSeries Package by Amir Khanshan 

Initializations 

 

> Typesetting:-mrow(Typesetting:-mi(
 

> Typesetting:-mrow(Typesetting:-mi(
 

>  
 

Analytic Calculations 

 

Given the function 

 

> Typesetting:-mrow(Typesetting:-mi(
 

piecewise(`<`(x, 0), 0, `<=`(0, x), x) (2.2.1)
 

>  
 

defined on Typesetting:-mrow(Typesetting:-mo(the trigonometric Fourier series would be generated by the fs command as follows. 

 

> Typesetting:-mrow(Typesetting:-mi(
 

 

 

 

 

Typesetting:-mrow(Typesetting:-mrow(Typesetting:-mfrac(Typesetting:-mn(
a[n] = piecewise(n = 0, `/`(1, 2), `/`(`*`(`+`(`-`(1), `^`(-1, n))), `*`(`^`(Pi, 2), `*`(`^`(n, 2))))), b[n] = `+`(`-`(`/`(`*`(`^`(-1, n)), `*`(Pi, `*`(n)))))
proc (N) options operator, arrow; `+`(`*`(`/`(1, 2), `*`(a0)), Sum(`+`(`*`(b(n), `*`(sin(`+`(`/`(`*`(2, `*`(Pi, `*`(n, `*`(t)))), `*`(T)))))), `*`(a(n), `*`(cos(`+`(`/`(`*`(2, `*`(Pi, `*`(n, `*`(t))))... (2.2.2)
 

>  
 

The Fourier coefficients Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi( and Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi( are now available as functions of the index Typesetting:-mrow(Typesetting:-mi(, as we see from the experiment 

 

> Typesetting:-mrow(Typesetting:-mi(
Typesetting:-mrow(Typesetting:-mi(
 

 

 

`+`(`-`(`/`(`*`(`/`(2, 9)), `*`(`^`(Pi, 2)))))
`+`(`/`(`*`(`/`(1, 3)), `*`(Pi))) (2.2.3)
 

>  
 

The decompose command applied to Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi( modifies its representation, taking into account the odd-even cycle produced by Typesetting:-mrow(Typesetting:-msup(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mo( in the numerator.  Thus, we have 

 

> Typesetting:-mrow(Typesetting:-mi(
 

piecewise(n = `+`(`*`(2, `*`(k))), 0, n = `+`(`*`(2, `*`(k)), `-`(1)), `+`(`-`(`/`(`*`(2), `*`(`^`(Pi, 2), `*`(`^`(n, 2))))))) (2.2.4)
 

>  
 

where, of course, the user has to know the appropriate integer (here 2) to include as a parameter. 

 

The fs command assigns to Typesetting:-mrow(Typesetting:-mi( the rule for generating partial sums of the Fourier series.  For example, we have 

 

> Typesetting:-mrow(Typesetting:-mi(
 

`+`(`/`(1, 4), Sum(`+`(`-`(`/`(`*`(`^`(-1, n), `*`(sin(`*`(Pi, `*`(n, `*`(x)))))), `*`(Pi, `*`(n)))), `*`(piecewise(n = 0, `/`(1, 2), `/`(`*`(`+`(`-`(1), `^`(-1, n))), `*`(`^`(Pi, 2), `*`(`^`(n, 2))))... (2.2.5)
 

>  
 

a display considerably improved with 

 

> Typesetting:-mrow(Typesetting:-mi(
 

`+`(`/`(1, 4), `/`(`*`(sin(`*`(Pi, `*`(x)))), `*`(Pi)), `-`(`/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))))), `*`(`^`(Pi, 2)))), `-`(`/`(`*`(`/`(1, 2), `*`(sin(`+`(`*`(2, `*`(Pi, `*`(x))))))), `*`(Pi))), `/`(`*`... (2.2.6)
 

>  
 

Thus, the argument 3 provides the partial sum 

 

Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi(  

 

The exponential form of the Fourier series for Typesetting:-mrow(Typesetting:-mi( is obtained with 

 

> Typesetting:-mrow(Typesetting:-mi(
 

 

 

Typesetting:-mrow(Typesetting:-munderover(Typesetting:-mo(
c[n] = piecewise(n = 0, `/`(1, 4), `+`(`/`(`*`(`/`(1, 2), `*`(`+`(`-`(1), `^`(-1, n), `*`(I, `*`(`^`(-1, n), `*`(Pi, `*`(n))))))), `*`(`^`(Pi, 2), `*`(`^`(n, 2)))))) (2.2.7)
 

>  
 

where now, the coefficients Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi( are provided as a function.  For example, we have 

 

> Typesetting:-mrow(Typesetting:-mi(
 

`+`(`/`(`*`(`/`(1, 18), `*`(`+`(`-`(2), `-`(`*`(`+`(`*`(3, `*`(I))), `*`(Pi)))))), `*`(`^`(Pi, 2)))) (2.2.8)
 

>  
 

and, again, the form of the coefficients can be modified by the decompose command, to  

 

> Typesetting:-mrow(Typesetting:-mi(
 

piecewise(n = `+`(`*`(2, `*`(k))), `/`(`*`(`*`(`/`(1, 2), `*`(I))), `*`(Pi, `*`(n))), n = `+`(`*`(2, `*`(k)), `-`(1)), `+`(`-`(`/`(`*`(`/`(1, 2), `*`(`+`(2, `*`(`*`(2, `*`(I)), `*`(Pi, `*`(`+`(`*`(`/`... (2.2.9)
 

>  
 

Unfortunately, with the parameter exp, the fs command does not provide a function that generates partial sums.  A partial sum of the exponential series has to be constructed from primitives, as per the following. 

 

> Typesetting:-mrow(Typesetting:-mi(
 

`+`(`/`(1, 4), `/`(`*`(`/`(1, 18), `*`(`+`(`-`(2), `*`(`*`(3, `*`(I)), `*`(Pi))), `*`(exp(`+`(`-`(`*`(`+`(`*`(3, `*`(I))), `*`(Pi, `*`(x))))))))), `*`(`^`(Pi, 2))), `-`(`/`(`*`(`+`(`*`(`/`(1, 4), `*`(... (2.2.10)
 

>  
 

Conversion to trigonometric form, and comparison with the corresponding partial sum from the trigonometric series is accomplished with either of the two commands 

 

> Typesetting:-mrow(Typesetting:-mi(
Typesetting:-mrow(Typesetting:-mi(
 

 

 

`+`(`/`(1, 4), `-`(`/`(`*`(`/`(2, 9), `*`(cos(`+`(`*`(3, `*`(Pi, `*`(x))))))), `*`(`^`(Pi, 2)))), `/`(`*`(`/`(1, 3), `*`(sin(`+`(`*`(3, `*`(Pi, `*`(x))))))), `*`(Pi)), `-`(`/`(`*`(`/`(1, 2), `*`(sin(`...
`+`(`/`(1, 4), `-`(`/`(`*`(`/`(2, 9), `*`(cos(`+`(`*`(3, `*`(Pi, `*`(x))))))), `*`(`^`(Pi, 2)))), `/`(`*`(`/`(1, 3), `*`(sin(`+`(`*`(3, `*`(Pi, `*`(x))))))), `*`(Pi)), `-`(`/`(`*`(`/`(1, 2), `*`(sin(`... (2.2.11)
 

>  
 

The fs command displays the formal Fourier series as part of its output.  This can be suppressed by assigning the variable showfs the value false.  Thus, the assignment 

 

> Typesetting:-mrow(Typesetting:-mi(
 

>  
 

leads to 

 

> Typesetting:-mrow(Typesetting:-mi(
 

a[n] = piecewise(n = 0, `/`(1, 2), `/`(`*`(`+`(`-`(1), `^`(-1, n))), `*`(`^`(Pi, 2), `*`(`^`(n, 2))))), b[n] = `+`(`-`(`/`(`*`(`^`(-1, n)), `*`(Pi, `*`(n))))) (2.2.12)
 

>  
 

and 

 

> Typesetting:-mrow(Typesetting:-mi(
 

c[n] = piecewise(n = 0, `/`(1, 4), `+`(`/`(`*`(`/`(1, 2), `*`(`+`(`-`(1), `^`(-1, n), `*`(I, `*`(`^`(-1, n), `*`(Pi, `*`(n))))))), `*`(`^`(n, 2), `*`(`^`(Pi, 2)))))) (2.2.13)
 

>  
 

Graphical Considerations 

 

Graphing Fourier series created with the fs command relies on Maple's plot command.  That is how the graph of the partial sum 

 

> Typesetting:-mrow(Typesetting:-mi(
 

`+`(`/`(1, 4), `-`(`/`(`*`(`/`(2, 9), `*`(cos(`+`(`*`(3, `*`(Pi, `*`(x))))))), `*`(`^`(Pi, 2)))), `/`(`*`(`/`(1, 3), `*`(sin(`+`(`*`(3, `*`(Pi, `*`(x))))))), `*`(Pi)), `-`(`/`(`*`(`/`(1, 2), `*`(sin(`... (2.3.1)
 

>  
 

appearing in Figure 1 is obtained. 

 

> Typesetting:-mrow(Typesetting:-mi(
 

Plot_2d  
 

Figure 1 

Graph of partial sum of Fourier series for Typesetting:-mrow(Typesetting:-mi( 

>  
 

The rept command in the package creates a data structure that permits Maple's plot command to draw the periodic extension of a function Typesetting:-mrow(Typesetting:-mi(  The periodic extension of  

 

> Typesetting:-mrow(Typesetting:-mi(
 

piecewise(`<`(x, 0), 0, `<=`(0, x), x) (2.3.2)
 

>  
 

a function whose domain is Typesetting:-mrow(Typesetting:-mo(appears in Figure 2. 

 

> Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi(
Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi(
 

Plot_2d  
 

Figure 2   Periodic extension based on rept command 

>  
 

The graph of a periodic extension and partial sum, seen in Figure 3, is constructed with the Maple display command from the plots package. 

 

> Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi(
Typesetting:-mrow(Typesetting:-mi(
 

Plot_2d  
 

Figure 3   Partial sum and periodic extension superimposed 

 

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.  
 

Image