Math 384

Partial Differential Equations

Spring 2004

Dr. Constant J. Goutziers

Department of Mathematical Sciences

goutzicj@oneonta.edu

Lesson 2

Generalized Fourier Series

Initializations

>    restart;
interface(showassumed=0);
with(plots):
assume(n, integer);
additionally(n>=1);

Warning, the name changecoords has been redefined

2.1

Examples

Example 2.1.1
Compute the Fourier cosine series for
f(x) = 1+x , on ( 0, Pi ).  Create a plot that shows the function f  and the partial sum of the first 20 terms of the Fourier cosine series on the interval [-3*Pi, 3*Pi] .

First code the orthonormal system, the inner product on ( 0, Pi ), and the function f .

>    phi[0]:=1/sqrt(Pi);
phi[n]:=sqrt(2/Pi)*cos(n*x);
dp:=(f,g)->int(f*g,x=0..Pi);
f:=1+x;

phi[0] := 1/(Pi^(1/2))

phi[n] := 2^(1/2)/Pi^(1/2)*cos(n*x)

dp := proc (f, g) options operator, arrow; int(g*f,x = 0 .. Pi) end proc

f := 1+x

Create the Fourier constants, also called Fourier coefficients.

>    c[0]:=dp(f, phi[0]);
c[n]:=dp(f, phi[n]);

c[0] := 1/2*Pi^(3/2)+Pi^(1/2)

c[n] := 2^(1/2)*(-1+(-1)^n)/Pi^(1/2)/n^2

>    ps:=unapply(simplify(c[0]*phi[0])+'sum'(c[n]*phi[n], n=1..m), (m,x));

ps := proc (m, x) options operator, arrow; 1/2*Pi+1+sum(2*(-1+(-1)^n)/Pi/n^2*cos(n*x),n = 1 .. m) end proc

>    p1:=plot(ps(20,x), x=-3*Pi..3*Pi):
p2:=plot(f, x=0..Pi, color=green, thickness=4):
display([p1, p2], scaling=constrained, view=[-3*Pi..3*Pi, 0..5]);

[Maple Plot]

>   

Example 2.1.2
Compute the Fourier sine series for
f(x) = 1+x , on ( 0, Pi ).  Create a plot that shows the function f  and the partial sum of the first 50 terms of the Fourier sine series on the interval [-3*Pi, 3*Pi] .

First code the orthonormal system, the inner product on ( 0, Pi ), and the function f .

>    phi[n]:=sqrt(2/Pi)*sin(n*x);
dp:=(f,g)->int(f*g,x=0..Pi);
f:=1+x;

phi[n] := 2^(1/2)/Pi^(1/2)*sin(n*x)

dp := proc (f, g) options operator, arrow; int(g*f,x = 0 .. Pi) end proc

f := 1+x

Create the Fourier coefficients.

>    c[n]:=dp(f, phi[n]);

c[n] := -2^(1/2)*(-1+(-1)^n+(-1)^n*Pi)/n/Pi^(1/2)

>    ps:=unapply('sum'(c[n]*phi[n], n=1..m), (m,x));

ps := proc (m, x) options operator, arrow; sum(-2*(-1+(-1)^n+(-1)^n*Pi)/n/Pi*sin(n*x),n = 1 .. m) end proc

>    p1:=plot(ps(50,x), x=-3*Pi..3*Pi):
p2:=plot(f, x=0..Pi, color=green, thickness=4):
display([p1, p2], scaling=constrained, view=[-3*Pi..3*Pi, -5..5]);

[Maple Plot]

>   

Example 2.1.3
Let  
f(x) = 1  on ( -Pi, 0 ) and f(x) = 1+x , on [ 0, Pi ) .  Compute the Fourier series for f , and create a plot that shows the function f  and the partial sum of the first 50 terms of the Fourier  series on the interval [-3*Pi, 3*Pi] .

First code the orthonormal system, the inner product on ( -Pi, Pi ), and the function f .

>    phi[0]:=1/sqrt(2*Pi);
phi[2*n]:=1/sqrt(Pi)*sin(n*x);
phi[2*n-1]:=1/sqrt(Pi)*cos(n*x);
dp:=(f,g)->int(f*g,x=-Pi..Pi);
f:=piecewise(-Pi<x and x<0, 1, 0<=x and x<Pi, 1+x, undefined);

phi[0] := 1/2*2^(1/2)/Pi^(1/2)

phi[2*n] := 1/Pi^(1/2)*sin(n*x)

phi[2*n-1] := 1/Pi^(1/2)*cos(n*x)

dp := proc (f, g) options operator, arrow; int(g*f,x = -Pi .. Pi) end proc

f := PIECEWISE([1, -Pi-x < 0 and x < 0],[1+x, -x <= 0 and x-Pi < 0],[undefined, otherwise])

Create the Fourier coefficients.

>    c[0]:=dp(f,phi[0]);
c[2*n]:=dp(f, phi[2*n]);
c[2*n-1]:=dp(f, phi[2*n-1]);

c[0] := 2^(1/2)*Pi^(1/2)+1/4*2^(1/2)*Pi^(3/2)

c[2*n] := -Pi^(1/2)/n*(-1)^n

c[2*n-1] := ((-1)^n-1)/Pi^(1/2)/n^2

>    ps:=unapply(simplify(c[0]*phi[0])+'sum'(c[2*n]*phi[2*n]+c[2*n-1]*phi[2*n-1], n=1..m), (m,x));

ps := proc (m, x) options operator, arrow; 1+1/4*Pi+sum(-1/n*(-1)^n*sin(n*x)+((-1)^n-1)/Pi/n^2*cos(n*x),n = 1 .. m) end proc

>    p1:=plot(ps(50,x), x=-3*Pi..3*Pi):
p2:=plot(f, x=-Pi..Pi, color=green, thickness=4):
display([p1, p2], scaling=constrained, view=[-3*Pi..3*Pi, 0..5]);

[Maple Plot]

>   

Example 2.1.4 (Problem 4, Section28, of the Textbook)
Find the Fourier series for
f(x) = exp(alpha*x) , on ( -Pi, Pi ), where alpha <> 0 .  Use Euler's formula exp(i*theta) = cos(theta)+i*sin(theta)  to write
a[n]+i*b[n] = 1/Pi*int(f(x)*exp(i*n*x),x = -Pi .. Pi) .  Then, take alpha = 1  and create a plot that shows the function f  and the partial sum of the first 100 terms of the Fourier  series on the interval [-3*Pi, 3*Pi] .

Note that I used exp(alpha*x)  instead of the book's exp(a*x) .  This is necessary in order to avoid programming confusion between the a  in exp(a*x)  and the a  in the coefficient a[n] .  Technically, a[n]  is an element of the table a  with alphanumeric index n .

First code the orthogonal  system {exp(i*n*x)} , the inner product on ( -Pi, Pi ), and the function f .

>    phi[0]:=1;
phi[n]:=exp(I*n*x);
dp:=(f,g)->int(f*g,x=-Pi..Pi);
assume(alpha, real);
f:=exp(alpha*x);

phi[0] := 1

phi[n] := exp(n*x*I)

dp := proc (f, g) options operator, arrow; int(g*f,x = -Pi .. Pi) end proc

f := exp(alpha*x)

Create the Fourier coefficients.  Note that, since the system {exp(i*n*x)}  is not normalized, an appropriate multiplicative constant 1/Pi  needs to be introduced for the computation of the Fourier coefficients, much like the formulas for a[n]  and b[n]   we derived in the beginning of the course.  

>    c[0]:=1/Pi*dp(f,phi[0]);
c[n]:=1/Pi*dp(f, phi[n]);

c[0] := 1/Pi*(-1+exp(2*Pi*alpha))/alpha*exp(-Pi*alpha)

c[n] := 1/Pi*(-1+exp(2*Pi*alpha))/(n*I+alpha)*(-1)^n*exp(-Pi*alpha)

Next, derive the formulas for a[0], a[n]  and b[n] , where n  is greater than or equal to 1 .

>    a[0]:=combine(convert(c[0], trig), trig);
a[n]:=combine(convert(Re(c[n]), trig), trig);
b[n]:=combine(convert(Im(c[n]), trig), trig);

a[0] := 2*sinh(Pi*alpha)/Pi/alpha

a[n] := 2*(-1)^n*alpha*sinh(Pi*alpha)/(Pi*alpha^2+Pi*n^2)

b[n] := -2*(-1)^n*n*sinh(Pi*alpha)/(Pi*alpha^2+Pi*n^2)

>    ps:=unapply(simplify(a[0]/2)+'sum'(map(factor, a[n]*cos(n*x)+b[n]*sin(n*x)), n=1..m), (m, x));

ps := proc (m, x) options operator, arrow; sinh(Pi*alpha)/Pi/alpha+sum(2*(-1)^n*alpha*sinh(Pi*alpha)*cos(n*x)/Pi/(alpha^2+n^2)-2*(-1)^n*n*sinh(Pi*alpha)*sin(n*x)/Pi/(alpha^2+n^2),n = 1 .. m) end proc

>    p1:=plot(subs(alpha=1, ps(100, x)), x=-3*Pi..3*Pi):
p2:=plot(subs(alpha=1, f), x=-Pi..Pi, color=green, thickness=4):
display([p1, p2], view=[-3*Pi..3*Pi, -1..exp(Pi)]);

[Maple Plot]

>