Symbolic computation of Fourier series
Wilhelm Werner Hochschule Heilbronn, Germany werner@hs-heilbronn.de 2006
Introduction:
This worksheet demonstrates the use of Maple for the symbolic computation of Fourier expansions.
This is an updated version of a package originally published in the Maple Application Center (2000).
Taylor series expansion is provided by Maple via the taylor or series command; there is no corresponding facility for Fourier expansions
however. The module FourierSeries designed for use with Maple 6 (or later) fills this gap. Real as well as complex Fourier coefficients are computed symbolically; furthermore some classroom visualizations are provided.
We do not give any applications of Fourier series here; for classroom introductions to this topic we refer to other contributions within the Maple Application Center. Instead we concentrate on the algorithms required to compute those expansions symbolically.
Acknowledgment
The author is indepted to Prof.Dr.Robert Lopez, Maplesoft, for several valuable comments which led to improvements of this package.
Section I: What makes symbolic computation of Fourier series cumbersome?
There are a lot of calculus texts which deal with the computation of Fourier coefficients; the relevant formulas e.g. on the interval [0,T] are well known:
The fact that the computation of these coefficients "only" requires integration seems to indicate that these computations are an easy task for a computer algebra system like Maple. This, however, is not the case as is demonstrated with the following simple example. Let us consider the function
A straightforward implementation of the above formulas on the interval [0,]
either results in an error message
Error, (in a) numeric exception: division by zero
or in coefficients which only cover the "generic case":
This result is wrong for k=0 and k=4! Assuming k to be integer forces Maple to do some a priori simplifications like
in the numerator which cause the problem. Probably many users encountered these problems and circumvented them by replacing symbolic integration with numerical integration methods. For graphical purposes this approach is acceptable, it is unsatisfactory in the context of computer algebra though.
Basically the approach which is taken by FourierSeries mimics hand calculation; the routine computes the generic solution and thereafter looks for critical cases. These exceptional cases are then handled separately.
The major problem of this approach is that the number of exceptional cases as well as their location is not known in advance. FourierSeries uses Maple's solve command to find exceptional cases and Maple's int command for integration; the limitations of the package therefore are basically determined by the limitations of these Maple procedures, which, however, are known to be extremely powerful. There is no internal maximum number of exceptional cases within FourierSeries; any example with an infinite set of exceptional points would result in a failure of FourierSeries, however.
Section II: Installation issues
FourierSeries is provided as a Maple module and therefore requires at least Maple 6 to work (for a version of the software for Maple V Rel.4 or Rel.5 contact the author); the software has been tested within the Windows 9x environment only so no claims whatsoever can be made for other platforms like Linux or Macintosh.
The easiest way to include FourierSeries into your Maple environment is to generate a directory/folder like
"C:\programs\Maple 6\UserLibs\FourierLib"
and copy all files into that directory. Within Maple change the libname according to
or change your Maple ini file accordingly. If you encounter an error message like
Error, (in with) invalid input: with expects its 1st argument, pname, to be of type {package, module}, but received FourierSeries
then most probably you provided an erroneous pathname within libname (check for "/" and "\"!) or you forgot to extend the libname variable.
You get help information in the usual manner:
One can call the routines of the module also directly without the with(FourierSeries); statement in the form
as well.
Section III: Examples
The following examples demonstrate the various options of FourierSeries:
Computation of real Fourier coefficients
The heart of FourierSeries is the procedure FourierCoeff for the computation of real and complex Fourier coefficients; FourierCoeff is called by all other routines of the package.
Alternatively you can use the FourierSin resp. FourierCos option:
In case of a piecewise linear function like
FourierCoeff supports a simplified input mechanism: The user has to provide a list of points only which describe the polygon:
The global variable _FourierSeriesShowFunction controls the display of the underlying function; this option is especially useful, if the user had provided a list of points only. (Note: The global variable _FourierSeriesShowPiecewise used in previous versions of the package is no longer supported.)
Computation of complex Fourier coefficients
Internally FourierSeries computes the complex Fourier expansion:
The coefficients c[k] are related to a[k] resp. b[k] via the equations
The complex Fourier coefficients can be computed with option FourierExp or FourierComplex:
Note that FourierCoeff returns a function which may be used to compute specific values of the Fourier coefficients:
Even or odd extensions of real functions defined on the positive resp. negative axis can be generated by
Real coefficients may be derived thereof via the above mentioned relations easily. It should be mentioned that
FourierCoeff also accepts parameters in the definition of functions or intervals:
In that case FourierCoeff makes suitable assumptions (e.g. parameters a real) for those parameters; the above formula obviously is not correct for all n if is an integer for example. It is up to the user to check which assumptions must be fulfilled in these cases:
The limitations of this feature is basically determined by Maple's int command; e.g.
In case Maple can't compute the integral symbolically FourierSeries also fails; of course any concrete instance is handled correctly:
Graphic output
Basically for educational purposes FourierSeries provides three formats for graphical output:
FourierPlot as well as FourierAnimate accept any plot options which apply to Maple's plot resp. animate command, e.g. title, legend, color etc.
The spectrum of a function is displayed by FourierSpectrum:
FourierSpectrum uses Maple's histogram command from the stats package; thus the plot options are restricted to those accepted by histogram.
Note: No graphics is generated if the function definition and/or interval contains additional parameters.
Error, (in FourierSeries:-FourierSpectrum) unspecified parameter(s), f
The plot procedures FourierPlot, FourierAnimate and FourierSpectrum support the simplified input mechanism for piecewise linear functions, too:
Application
It is well known, that global smoothness properties of the periodic continuation of a function determine how fast Fourier coefficients tend to zero; this can be demonstrated easily as follows:
1. discontinuity ("jump"); coefficients are O():
2. continous; discontinuous first derivative; the coefficients are O():
3. first, second derivative continous, third derivative has a jump discontinuity; therefore the coefficients are O():
References
FourierSeries is one of the routines developped by the author for the (german) book
W.Werner, Mathematik lernen mit Maple, Band 2, dpunkt.verlag, Heidelberg 1998,
ISBN 3-920993-94-2 (633 p., CD included) (out of print)
Conclusion:
FourierSeries extends Maple's capabilities to compute symbolically the coefficients of Fourier series..
Legal Notice: The copyright for this application is owned by the author(s). Neither Maplesoft nor the author are responsible for any errors contained within and are not liable for any damages resulting from the use of this material. This application is intended for non-commercial, non-profit use only. Contact the author for permission if you wish to use this application in for-profit activities.