Application Center - Maplesoft

App Preview:

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

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 4
 

Robert J. Lopez 

Emeritus Professor of Mathematics and Maple Fellow 

Maplesoft 

Initializations 

> Typesetting:-mrow(Typesetting:-mi(
> with(plots); -1

Once the files for the Fourier package by Karel Srot are in place, the following command will load its code. 

> with(Fourier); -1

 

The Fourier Package by Karel Srot 

In this fourth (and final) article in a series devoted to Maple implementations of Fourier series calculations, we describe the Fourier package announced by Karel Srot in a post to MaplePrimes on August 21, 2006.  Instructions for downloading and  installing the package are available at www.math.muni.cz/~xsrot/frady.  Although the author notes that this site is primarily in Czech, obtaining the code is straightforward.  Installation instructions within the download are in English. 

Although a significant portion of the functionality in this package is available elsewhere, the nuances of the commands make for a different feel to the package.  In addition, there is a Fourier series Maplet that is worth considering.  Recall that 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 FourierSeries package by Amir Khanshan.  In the third article in this series, we described the FourierSeries package provided to the Maple Application Center by Wilhelm Werner.  

Table of Commands 

Table 1 summarizes the commands available in Karel Srot's Fourier package.  Note that there are help pages for seven of the eight commands listed when the package is loaded via the with(Fourier) command.  The LimitFunction command has no help page and appears to have been superceded by the PeriodicExtension command. 

Command 

Principal Argument 

Usage 

FSeriesOfFunction 

Typesetting:-mrow(Typesetting:-mi( 

Provides formal Fourier series 

GetPartialSum 

Series 

Provides a partial sum of the Fourier series 

FSeriesNthTerm 

Series 

Provides Typesetting:-mrow(Typesetting:-msup(Typesetting:-mi( term of the Fourier series 

FourierCoeff 

Typesetting:-mrow(Typesetting:-mi( 

For specified Typesetting:-mrow(Typesetting:-mi(, provides Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi(a list of the Typesetting:-mrow(Typesetting:-msup(Typesetting:-mi( Fourier coefficients 

AnimGraphOfFSeries 

Series 

Provides sequence of partial sums graphed atop Typesetting:-mrow(Typesetting:-mi( 

PeriodicExtension 

Typesetting:-mrow(Typesetting:-mi( 

Provides graph of periodic extension of Typesetting:-mrow(Typesetting:-mi(and optionally shows points at Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mover(Typesetting:-mi(if Typesetting:-mrow(Typesetting:-mover(Typesetting:-mi( is a point of discontinuity 

DeviationOfPartialSums 

Series 

Calculates and displays values of Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi(or of the differences Typesetting:-mrow(Typesetting:-mi(at any specific Typesetting:-mrow(Typesetting:-mover(Typesetting:-mi(  

Table 1   Commands in Karel Srot's Fourier package.  "Series" is the object returned by the FSeriesOfFunction command, whereas Typesetting:-mrow(Typesetting:-mi( is the function whose Fourier series is computed. 

 

Computing a Fourier Series 

A Fourier series for a function is obtained with the FSeriesOfFunction command.  For example, if the function is given by 

> `:=`(f, proc (x) options operator, arrow; `+`(`*`(`^`(x, 2)), x) end proc); -1
('f')(x) = f(x)
f(x) = `+`(`*`(`^`(x, 2)), x)

 

on the interval Typesetting:-mrow(Typesetting:-mo(its Fourier series is given by 

> `:=`(F, FSeriesOfFunction(f, -2 .. 2))
`+`(`/`(4, 3), Sum(`+`(`/`(`*`(16, `*`(`^`(-1, n), `*`(cos(`+`(`*`(`/`(1, 2), `*`(Pi, `*`(n, `*`(x))))))))), `*`(`^`(Pi, 2), `*`(`^`(n, 2)))), `/`(`*`(4, `*`(`^`(-1, `+`(1, n)), `*`(sin(`+`(`*`(`/`(1,...
 

 

Notice that the Fourier coefficients are not returned as separate entities, but are embedded in a formal representation of the resulting series. 

A partial sum of the series is obtained with the GetPartialSum command.  For example, the partial sum containing the terms 

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

would be obtained with 

> GetPartialSum(F, 2)
`+`(`/`(4, 3), `-`(`/`(`*`(16, `*`(cos(`+`(`*`(`/`(1, 2), `*`(Pi, `*`(x))))))), `*`(`^`(Pi, 2)))), `/`(`*`(4, `*`(sin(`+`(`*`(`/`(1, 2), `*`(Pi, `*`(x))))))), `*`(Pi)), `/`(`*`(4, `*`(cos(`*`(Pi, `*`(...

 

where Typesetting:-mrow(Typesetting:-mi(and Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi(  

A graph of the periodic extension of Typesetting:-mrow(Typesetting:-mi(visible in Figure 1, is obtained with the PeriodicExtension command. 

> PeriodicExtension(f, -2 .. 2, -6 .. 5.9, scaling = constrained)

 

Plot_2d

Figure 1   Periodic extension of Typesetting:-mrow(Typesetting:-mi( 

 


Because at each Typesetting:-mrow(Typesetting:-mi( the Fourier series converges to Typesetting:-mrow(Typesetting:-mfrac(Typesetting:-mn(at discontinuities or at endpoints of intervals where initial and final values do not agree, the graph of the limit function for the Fourier series may not be identical to the graph of the periodic extension.  Indeed, for Typesetting:-mrow(Typesetting:-mi( given above, the limit function for the Fourier series is the function sketched in Figure 2. 

> PeriodicExtension(f, -2 .. 2, -6 .. 5.95, scaling = constrained, showlimitpoints)

 

Plot_2d

Figure 2   Limit function for Fourier series of Typesetting:-mrow(Typesetting:-mi( 

 


At discontinuities, the series converges to the midpoint of the jump. 

A graph of Typesetting:-mrow(Typesetting:-mi( and a partial sum of its Fourier series can be obtained with the AnimGraphOfFSeries command.  Figure 3 shows a graph of Typesetting:-mrow(Typesetting:-mi( and the partial sum for which Typesetting:-mrow(Typesetting:-mi( 

> `:=`(pf, plot(f, -2 .. 2, color = black)); -1
AnimGraphOfFSeries(F, [2], -2 .. 2, [pf], scaling = constrained)

 

Plot_2d

Figure 3   In black, graph of Typesetting:-mrow(Typesetting:-mi(and in red, partial sum for which Typesetting:-mrow(Typesetting:-mi( 

 

An animation of the convergence of a sequence of partial sums to the limit function appears in Figure 4. 

> `:=`(pl, PeriodicExtension(f, -2 .. 2, -2 .. 2.3, showlimitpoints)); -1
AnimGraphOfFSeries(F, [seq(k, k = 0 .. 10)], -2 .. 2, [pl], insequence = true)

 

Plot_2d

Figure 4   Animation of the convergence of partial sums Typesetting:-mrow(Typesetting:-mi(to limit function 

 


The command FSeriesNthTerm provides a specific Typesetting:-mrow(Typesetting:-mi(th term of the Fourier series expansion, whereas the FourierCoeff command provides the coefficient of the Typesetting:-mrow(Typesetting:-mi(th term.   

For example, the second term and the corresponding coefficient(s) of the series 

> F
`+`(`/`(4, 3), Sum(`+`(`/`(`*`(16, `*`(`^`(-1, n), `*`(cos(`+`(`*`(`/`(1, 2), `*`(Pi, `*`(n, `*`(x))))))))), `*`(`^`(Pi, 2), `*`(`^`(n, 2)))), `/`(`*`(4, `*`(`^`(-1, `+`(1, n)), `*`(sin(`+`(`*`(`/`(1,...

 

are obtained with 

> FSeriesNthTerm(f, -2 .. 2, 2)

 

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

and 

> FourierCoeff(f, -2 .. 2, 2)

 

[`+`(`/`(`*`(4), `*`(`^`(Pi, 2)))), `+`(`-`(`/`(`*`(2), `*`(Pi))))]

 

respectively. 

Bessel's Inequality 

 

Although it can be generalized for arbitrary complete orthonormal sets of functions, Bessel's inequality for the Fourier series can be written as 

Typesetting:-mrow(Typesetting:-mfrac(Typesetting:-msubsup(Typesetting:-mi(   

In order to examine how close this inequality comes to being an equality, the Fourier package contains the DeviationOfPartialSums command, which computes  

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

for given partial sums Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi(, and plots a bar-graph of the values of Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi( as a function of the index Typesetting:-mrow(Typesetting:-mi(.  For example, we would have Figure 5 if the command is applied to the function Typesetting:-mrow(Typesetting:-mi( 

> DeviationOfPartialSums(f, F, -2 .. 2, 5, printvalues = true)

 

 

 

 

[3.319973227, 1.588635086, 1.176724494, .9795592328, .8581153517]
Plot_2d

Figure 5   Values of Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi(for Typesetting:-mrow(Typesetting:-mi(  

 


The numbers in the list above the graph are the value of Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi(.  We can corroborate this claim by computing the Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi( directly, via 

> for k from 0 to 4 do evalf(sqrt(int(`*`(`^`(`+`(f(x), `-`(GetPartialSum(F, k))), 2)), x = -2 .. 2))) end do
 

 

 

 

 

 

 

 

 

 

 

 

3.319973227
1.588635085
1.176724493
.9795592315
.8581153524
 

 

Notice that the DeviationOfPartialSums command returns Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi(when given the parameter Typesetting:-mrow(Typesetting:-mi(

The difference Typesetting:-mrow(Typesetting:-mi( at a particular value of Typesetting:-mrow(Typesetting:-mi( can also be obtained with the DeviationOfPartialSums command.  In fact, both the values and a bar-graph of the values are available, as we see in Figure 6.  

> DeviationOfPartialSums(f, F, 1, 5, printvalues = true)

 

 

 

 

[.6666666667, -.6065728773, -.2012881429, .2231250381, .1218038545]
Plot_2d

Figure 6   The difference Typesetting:-mrow(Typesetting:-mi(for Typesetting:-mrow(Typesetting:-mi(  

 

 

That Figure 6 actually produces the differences claimed is verified by the following direct calculation of these differences. 

> for k from 0 to 4 do evalf(`+`(f(1), `-`(eval(GetPartialSum(F, k), x = 1)))) end do
 

 

 

 

 

 

 

 

 

 

 

 

.6666666667
-.6065728773
-.2012881429
.2231250381
.1218038545

 

Fourier Series Maplet 

While not an integral component of the Fourier package written by Karel Srot, a Fourier series maplet based on the package is available.  Its application is detailed in Figures 7-9.  In Figure 20, we see the result of what is essentially the FSeriesOfFunction command.  The tildes visible in the maplet window appear in Maple 10, but not in Maple 11. 

Image 

Figure 7   Fourier series for Typesetting:-mrow(Typesetting:-mi( generated by Maplet 

Figure 8 shows a partial sum displayed in the window opened via the "Open window for computing partial sums" button on the left in the main maplet.  

 

Image 

Figure 8 

Partial sum generated by "Open window for computing partial sums" button 

Figure 9 displays the partial sum Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi(one frame of an animation that shows the convergence of partial sums to the limit function for the Fourier series corresponding to the function Typesetting:-mrow(Typesetting:-mi(

Image 

Figure 9 

Animation of convergence of partial sums Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi( to Typesetting:-mrow(Typesetting:-mi( Visible is Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi( 

 

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