Fourier_Series.mws

Fourier Series Expansions of Functions

Dr. M. Leigh Lunsford

In this worksheet we will examine the Fourier Series expansions of several functions.

Example 1 - A Piecewise Smooth Function

We first define our piecewise smooth function and plot it:

> restart:

> g := x -> piecewise(x<=0,0, x<=3,x):
plot(g,-3..3, scaling=constrained, title="Plot of Piecewise Smooth Function g" );

[Maple Plot]

Next we find the coeficients for the Fourier series:

The coefficients, b[n] , for the sine terms are given by the integral b[n] = 1*Int(g(x)*sin(n*Pi*x/3),x = -3 .. 3)/3 .

> assume(n,integer); bn := simplify((1/3)*int(g(x)*sin(n*Pi*x/3),x=-3..3));

bn := 3*(-1)^(1+n)/n/Pi

and the coeffiecients for the cosine terms, a[n] , of the series are given by the integral a[n] = 1*Int(g(x)*cos(n*Pi*x/3),x = -3 .. 3)/3 .

and the coefficient a[0] is given by the integral a0 := 1*Int(g(x),x = -3 .. 3)/6 .

> a0:=(1/6)*int(g(x),x=-3..3);

a0 := 3/4

> an := simplify((1/3)*int(g(x)*cos(n*Pi*x/3),x=-3..3));

an := 3*((-1)^n-1)/n^2/Pi^2

Let's compute a few of the partial sums of the series and plot them with the original function f .

> u1 := a0+sum(an*cos(n*Pi*x/3) + bn*sin(n*Pi*x/3),n=1..1):

> u2 := a0+sum(an*cos(n*Pi*x/3) + bn*sin(n*Pi*x/3),n=1..2):

> u4 := a0+sum(an*cos(n*Pi*x/3) + bn*sin(n*Pi*x/3),n=1..4):

> u10 := a0+sum(an*cos(n*Pi*x/3) + bn*sin(n*Pi*x/3),n=1..10):

> u20 := a0+sum(an*cos(n*Pi*x/3) + bn*sin(n*Pi*x/3),n=1..20):

Now we will plot each of these partial sums with the original function. We will plot the partial sums in red and the function in black. Examine the convergence of the series. Verify that the convergence theorems of Section 14.2 predict this behavior. What do you think is happening with the series outside the interval from x = -3 to x = 3 ? Also see if you can understand how the Gibss phenomenon is illustrated in these plots.

> plot([g(x),u1], x = -3..3, color=[black,red], scaling=constrained,title="Partial Sum for n=1");

[Maple Plot]

> plot([g(x),u2], x = -3..3, color=[black,red], scaling=constrained,title="Partial Sum for n=2");

[Maple Plot]

> plot([g(x),u4], x = -3..3, color=[black,red], scaling=constrained,title="Partial Sum for n=4");

[Maple Plot]

> plot([g(x),u10], x = -3..3, color=[black,red], scaling=constrained,title="Partial Sum for n=10");

[Maple Plot]

> plot([g(x),u20], x = -3..3, color=[black,red], scaling=constrained,title="Partial Sum for n=20");

[Maple Plot]

> plot(u20, x = -6..6, color=[black,red], scaling=constrained,title="Partial Sum for n=20");

[Maple Plot]

>

Example 2 - Fourier Series of an Easy Odd Function ( f(x) = x )

> restart:

This is a more detailed example of the example you have in your text on pages 676 and 677. We will expand f(x) = x into its Fourier Series on the interval from x = -Pi to x = Pi .

First we define the function and find its Fourier coefficients:

> f:=x->x;

f := proc (x) options operator, arrow; x end proc

Of course we know how this graph looks but we will plot it here for reference (and also for you to review the plot command)

> plot(f,-Pi..Pi,color=black, scaling=constrained);

[Maple Plot]

Now we find the Fourier coefficients of f . Since f is odd we know that we will only have coefficients for the sine terms of the series.

> q := (2/(Pi))*Int(f(x)*sin(n*Pi*x/Pi),x=0..Pi);

q := 2/Pi*Int(x*sin(n*x),x = 0 .. Pi)

> assume(n,integer); b := combine(value(q),trig);

b := -2/n*(-1)^n

So, the Fourier Series looks like Sum(b[n]*sin(n*x),n = 1 .. infinity) , where b[n] = -2*(-1)^n/n . Let's compute a few of the partial sums of the series and plot them with the original function f .

> u1 := sum(b*sin(n*x),n=1..1):

> u2 := sum(b*sin(n*x),n=1..2):

> u3 := sum(b*sin(n*x),n=1..3):

> u4 := sum(b*sin(n*x),n=1..4):

> u10 := sum(b*sin(n*x),n=1..10):

> u20 := sum(b*sin(n*x),n=1..20):

> u30 := sum(b*sin(n*x),n=1..30):

> u40 := sum(b*sin(n*x),n=1..40):

Now we will plot each of these partial sums with the original function. We will plot the partial sums in red and the function in black. Examine the convergence of the series. Verify that the convergence theorems of Section 14.2 predict this behavior. What do you think is happening with the series outside the interval from x = -Pi to x = Pi ? Also see if you can understand how the Gibss phenomenon is illustrated in these plots.

> plot([f(x),u1], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=1");

[Maple Plot]

> plot([f(x),u2], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=2");

[Maple Plot]

> plot([f(x),u3], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=3");

[Maple Plot]

> plot([f(x),u4], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=4");

[Maple Plot]

> plot([f(x),u10], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=10");

[Maple Plot]

> plot([f(x),u20], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=20");

[Maple Plot]

> plot([f(x),u30], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=30");

[Maple Plot]

> plot([f(x),u40], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=40");

[Maple Plot]

>

Example 3 - Fourier Sine and Cosine Series of a Discontinuous Function

We now look at a function where the function is no longer defined on an interval of the form -L to L but instead on an interval of the form 0 to L . Here we will let L = Pi and define our function below. This is essentially the same function use in Example 14.18 of your texton page 688.

> restart:

> f := x -> piecewise(x<=0,0,x<=Pi/2,1, x<=Pi, 2):

> plot(f,0..Pi, scaling=constrained, title="Plot of Function f");

[Maple Plot]

>

Now we find our Fourier sine and cosine series for this function:

Fourier Sine Series

We first compute the Fourier sine series of f . The coefficients of this series are given by the integral b[n] = 2*Int(f(x)*sin(n*Pi*x/Pi),x = 0 .. Pi)/Pi .

> assume(n,integer); bn := simplify((2/(Pi))*int(f(x)*sin(n*Pi*x/Pi),x=0..Pi));

bn := 2/Pi*(2*(-1)^(1+n)+cos(1/2*Pi*n)+1)/n

So, the Fourier Sine Series looks like Sum(b[n]*sin(n*x),n = 1 .. infinity) . Let's compute a few of the partial sums of the series and plot them with the original function f .

> u1 := sum(bn*sin(n*x),n=1..1):

> u2 := sum(bn*sin(n*x),n=1..2):

> u3 := sum(bn*sin(n*x),n=1..3):

> u4 := sum(bn*sin(n*x),n=1..4):

> u10 := sum(bn*sin(n*x),n=1..10):

> u20 := sum(bn*sin(n*x),n=1..20):

> u30 := sum(bn*sin(n*x),n=1..30):

> u40 := sum(bn*sin(n*x),n=1..40):

Notice in the plots below that I plotted over the interval -Pi to Pi . (Why do you think I did this??)

> plot([f(x),u1], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=1");

[Maple Plot]

> plot([f(x),u2], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=2");

[Maple Plot]

> plot([f(x),u3], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=3");

[Maple Plot]

> plot([f(x),u4], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=4");

[Maple Plot]

> plot([f(x),u10], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=10");

[Maple Plot]

> plot([f(x),u20], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=20");

[Maple Plot]

> plot([f(x),u30], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=30");

[Maple Plot]

> plot([f(x),u40], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=40");

[Maple Plot]

>

Fourier Cosine Series

We next compute the Fourier cosine series of f . The coefficients, a[n] , of this series are given by the integral a[n] = 2*Int(f(x)*cos(n*Pi*x/Pi),x = 0 .. Pi)/Pi and a[0] is given by the integral 1*int(f(x),x = 0 .. Pi)/Pi .

> an := simplify((2/(Pi))*int(f(x)*cos(n*Pi*x/Pi),x=0..Pi));

an := -2/Pi*sin(1/2*Pi*n)/n

> a0:=simplify((1/(Pi))*int(f(x),x=0..Pi));

a0 := 3/2

So, the Fourier Cosine Series looks like a[0]+Sum(a[n]*cos(n*x),n = 1 .. infinity) . Let's compute a few of the partial sums of the series and plot them with the original function f .

> u1 := a0+sum(an*cos(n*x),n=1..1):

> u2 := a0+sum(an*cos(n*x),n=1..2):

> u3 := a0+sum(an*cos(n*x),n=1..3):

> u4 := a0+sum(an*cos(n*x),n=1..4):

> u10 := a0+sum(an*cos(n*x),n=1..10):

> u20 := a0+sum(an*cos(n*x),n=1..20):

> u30 := a0+sum(an*cos(n*x),n=1..30):

> u40 := a0+sum(an*cos(n*x),n=1..40):

Notice in the plots below that I plotted over the interval -Pi to Pi . (Why do you think I did this??)

> plot([f(x),u1], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=1");

[Maple Plot]

> plot([f(x),u2], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=2");

[Maple Plot]

> plot([f(x),u3], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=3");

[Maple Plot]

> plot([f(x),u4], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=4");

[Maple Plot]

> plot([f(x),u10], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=10");

[Maple Plot]

> plot([f(x),u20], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=20");

[Maple Plot]

> plot([f(x),u30], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=30");

[Maple Plot]

> plot([f(x),u40], x = -Pi..Pi, color=[black,red], scaling=constrained,title="Partial Sum for n=40");

[Maple Plot]

>

>

>