Day 09

Tuesday, Feb 28, 2017

# Ch 3 Fourier Series

## Motivation

Can we find a mixture of the following solutions of our PDE to match any given boundary function around the outside?

## Definition

Periodic extension of f on [-L,L).

Convergence? Let's explore a little ... we can compute the integrals for the Fourier coefficients numerically:

%matplotlib inline
import matplotlib.pyplot as pl
from numpy import *
from scipy.integrate import quadrature

def draw(f,filenameprefix,M):
def ai(x,n): return f(x)*cos(n*pi*x/L)
def bi(x,n): return f(x)*sin(n*pi*x/L)
a0 =            (quadrature(ai,-L,0,args=(0))[0] + quadrature(ai,0,L,args=(0))[0])/2  # (Splitting it in two to make quadrature
def a(n): return quadrature(ai,-L,0,args=(n))[0] + quadrature(ai,0,L,args=(n))[0]     #  easier if there is a discontinuity at 0)
def ff(x,m): return a0*ones_like(x) + array([a(n)*cos(n*pi*x/L) + b(n)*sin(n*pi*x/L) for n in range(1,m+1)]).sum(axis=0)
x = linspace(-L,L,600)
fx = f(x)
for m in range(0,M+1):
pl.figure(figsize=(12,4))
pl.subplot(1,2,1); pl.plot(x,fx,'b',alpha=0.5,lw=3)
foux = ff(x,m)
pl.subplot(1,2,1); pl.plot(x,foux   ,'k'); pl.title('f itself (blue) and Fourier partial sum to '+str(m))
pl.subplot(1,2,2); pl.plot(x,foux-fx,'r'); pl.title('Error with terms up to n='+str(m)+' included')
pl.savefig(filenameprefix+'_'+str(m)+'.png')


## A perfectly nice example

This function has continous periodic extension:

f(x) = esin((nπx)/(L))

and the Fourier series converges to f rapidly.

I am computing the integrals for the Fourier coefficients numerically.

L = 1
def f(x): return exp(sin(pi*x/L))
draw(f,'expsin',3)


## An example with a jump discontinuity

def f(x):
fx = x+L
fx[x>0] -= 2*L
return fx

draw(f,'expsin',3)


We see overshooting. Nevertheless, the Fourier series converges to f(x) at every x except the point of discontinuity:

## An example where we can easily compute the Fourier coefficients exactly

The periodic extension of this function has a jump disconinuity at ±10, ±30, ±50... and at ...,  − 23,  − 3, 23, 43, ....

We see the Gibbs overshoot: