Linear Methods of Applied Mathematics

Differentiating Fourier Series

(c) Copyright 1994-1997 by Evans M. Harrell II and James V. Herod. 
     All rights reserved.

Notes for the instructor.

This contains calculations and examples which correlate with chapter 5 of the WWW text by Harrell and Herod.

Students can be encouraged to cut and paste from this notebook to do homework.

Instructions

This notebook uses Mathematica  to perform calculations for Harrell and Herod's hypertext book, Linear Methods of Applied Mathematics.   The student needs only a basic knowledge of Mathematica  to use the notebook, which is designed both to show how to work problems in the text and to provide a template for using Mathematica  to work other problems of the student's own design.  

Calculations will be performed when the reader presses enter in a given calculation cell (bold print).  It is best to activate the cells in order, so that Mathematica  will be able to call on operators and functions defined in earlier cells.  Red color coding is used to warn the reader when a given calculation relies on an earlier one.

A useful substitution, which we shall often make, is:

TrigId = {Cos[Pi n_] -> (-1)^n, Sin[Pi n_] -> 0};

Please activate this cell before proceeding.

Introduction.

Some of the most important purposes for which Fourier series are used are to solve differential equations.  We shall therefore wish to differentiate them, and it is reasonable to wonder whether this is legitimate - it is not always legitimate to differentiate an infinite series.  Fortunately, Fourier series are robust enough that differentiating them normally works quite well.

Let's begin by recalling how to set Mathematica up to calculate Fourier series, from the Mathematica notebook for Chapter 4:

Automating the Fourier series

Here we set up some Mathematica  commands to compute the Fourier for a general function defined on an interval a < x < b.  Warning!  We do not recommend running these commands on a computer with a slow processor, since there are several nested definitions and integrations.  If you find yoursefl limited by the capabilities of your machine, it is recommended that you calculate the coefficients first, and then insert them into the series with a separate definition, as in the examples above.

Ave[f_, {a_,b_}] := (1/(b-a)) Integrate[(f /. x -> intvar1),                        {intvar1, a, b}]
A[f_,m_, {a_,b_}] := (2/(b-a)) Integrate[              (Cos[2 m Pi intvar2/(b-a)] f /. x -> intvar2),               {intvar2, a, b}]  /. TrigId
B[f_,n_, {a_,b_}] := (2/(b-a)) Integrate[              (Sin[2 n Pi intvar3/(b-a)] f /. x -> intvar3),                  {intvar3, a, b}]  /. TrigId

FullSeries[f_, NN_, {x_,a_,b_}] := Ave[f,{a,b}] +       Sum[A[f,m,{a,b}] Cos[2 m Pi x/(b-a)], {m, 1, NN}] +       Sum[B[f,n,{a,b}] Sin[2 n Pi x/(b-a)], {n, 1, NN}]

An example:

FullSeries[x, 3, {x,0,1}]

Example:  Differentiating the series for x - x3.

In the notebook for chapter 4 we calculated the Fourier series for the function 
          x - x3, 
and found a series with only sine contributions (because the function is odd):

FSeries[x_, N_] = Sum[-12 (-1)^k Sin[ Pi k x ] /(k Pi)^3, {k, 1, N} ]

Plot[{x-x^3, FSeries[x,3]}, {x,-1,1}]

The match is superb.   But what happens if we differentiate?  Is the derivative of a Fourier series the series for the derivative?  If so, that can save us a lot of work, since it is easy to differentiate a Fourier series term by term.

Supposing this works, the series for the derivative 1 - 3 x^2 should be:

D[FSeries[x,N],x]

%/. N -> 4

Plot[{1 - 3 x^2, %}, {x, -1,1}]

Superb!  Just for fun, let's see the comparison outside the interval where we cut off the polynomials:

Plot[{1 - 3 x^2, %%}, {x, -Pi,Pi}]

Finally, let us calculate the Fourier series for 1 - 3 x^2 and see that the integral formulae give us the same series:

f[x_] := 1 - 3 x^2

Ave[f[x], {-1,1}]
A[f[x],m, {-1,1}]
B[f[x],n, {-1,1}]

NewSeries[x_, NN_] := Sum[12 ((-1)^(m+1)/(m Pi)^2 )                   Cos[m Pi x], {m,1,NN}]

NewSeries[x, 4]

Indeed the same as predicted.

The general rule is :  The Fourier series is very robust.  When it is manipulated in almost any reasonable way, correct and consistent answers result.

Example:  Integrating the series for x - x3.

Suppose now that we try integrating a Fourier series term by term.  If c[0] (which = a[0]) is different from 0, we get another Fourier series!  If c[0] is not 0, then we would only get another Fourier series after replacing the function x with a Fourier series, but we won't consider that case now.

Does the integrated series converge to the integral of the original function?  According to our experiment with differentiation, it seems so.  Let us do an experiment, by integrating x - x^3.  As before:

FSeries[x_, N_] = Sum[-12 (-1)^k Sin[ Pi k x ] /(k Pi)^3, {k, 1, N} ]

Mathematica had difficulties with this one, but it is easy to integrate by hand:

IntegratedSeries = Sum[12 (-1)^k Cos[ Pi k x ] /(k Pi)^4, {k,1,N} ]

% /. N -> 3

Plot[{x^2/2 - x^4/4, %}, {x,-1,1}]

Why don't they match?  The answer lies in the choice of the constant of integration.  The method we used gives us the integral with average 0.  This is not the case for x^2/2 - x^4/4.

The lesson is:  When integrating a Fourier series, take some care about the  constant terms.