Linear Methods of Applied Mathematics
Differentiating Fourier series


This is an evaluated Mathematica notebook. Since the notebook is intended to be interactive, it may be helpful to also view the unevaluated version

In[1]:=

  (c) Copyright 1994,1995 by Evans M. Harrell, II.  All rights reserved

Differentiating Fourier series. Let's begin by reminding Mathematica about
some identities we will use:

In[2]:=

  R1 = {Cos[Pi n_] -> (-1)^n, Sin[Pi n_] -> 0}
  Clear[c]
  Clear[f]

In this notebook we will use the complex form of the Fourier series. As you
recall, the complex series is completely equivalent to the full real series, with
both sines and cosines. You may find it instructive to set the calculations
up with the real functions for comparison. The complex Fourier coefficients
for a function f on an interval (a,b) are given by the formula:

In[3]:=

  c[k_,f_,a_,b_] := (1/(b-a)) Integrate[f[x] Exp[-2 Pi I k x/(b-a)], {x,a,b}]

In[4]:=

  f[x_] := 1

In[5]:=

  c[k,f,0,Pi]

Out[5]=

  -I   I  -2 I k Pi
  --   - E
  2    2
  -- + ------------
  k         k
  -----------------
         Pi

In[6]:=

  % /. k -> 2

Out[6]=

  0

In[7]:=

  %% /. k -> 3

Out[7]=

  0

In[8]:=

  c[0,f,0,Pi]

Out[8]=

  1

Recall that % refers to the previous calculation, %% to the one before that,
etc. The phrase /. k -> 3 tells Mathematica to evaluate the expression with
the additional rule that k = 3.

So, we appear to be up and running. A question to ponder: What would
have happened if I had written %%% /. k -> 0 in the line above?

Let's now calculate some more series. Suppose that

In[9]:=

  f[x_] := x - x^3

In[10]:=

  c[k,f,-1,1] /.{E^(I Pi k) -> (-1)^k,E^(-I Pi k) -> (-1)^k}

Out[10]=

         k                    2   2
     (-1)  (6 - 6 I k Pi - 2 k  Pi )
  (-(-------------------------------) +
                  4   4
                 k  Pi

          k                    2   2
      (-1)  (6 + 6 I k Pi - 2 k  Pi )
      -------------------------------) / 2
                   4   4
                  k  Pi

In[11]:=

  Simplify[%]

Out[11]=

          k
  6 I (-1)
  ---------
    3   3
   k  Pi

If we want a plot, it will be best to use real quantities, so recall that this is
an odd function, with only sines in the usual Fourier series.

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

In[12]:=

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

Out[12]=

              k
      -12 (-1)  Sin[k Pi x]
  Sum[---------------------, {k, 1, N}]
              3   3
             k  Pi

In[13]:=

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

Out[13]=

  -Graphics-

Wonderful! What happens if we differentiate? We get either the formula
1 - 3 x^2 or else the series

In[14]:=

  D[FSeries[x,N],x]

Out[14]=

              k
      -12 (-1)  Cos[k Pi x]
  Sum[---------------------, {k, 1, N}]
              2   2
             k  Pi

In[15]:=

  %/. N -> 4

Out[15]=

  12 Cos[Pi x]   3 Cos[2 Pi x]   4 Cos[3 Pi x]
  ------------ - ------------- + ------------- -
        2               2                2
      Pi              Pi             3 Pi

    3 Cos[4 Pi x]
    -------------
            2
        4 Pi

In[16]:=

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

Out[16]=

  -Graphics-

Super! Just for fun, let's see the comparison outside the interval where we
cut off the polynom