Application Center - Maplesoft

App Preview:

Fourier Series

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application


 

FourierSeries.mws

Fourier Series

Anton Dzhamay

Department of Mathematics

The University of Michigan

Ann Arbor, MI 48109

wPage: http://www.math.lsa.umich.edu/~adzham

email: adzham@umich.edu

Copyright  2004  by Anton Dzhamay

All rights reserved

Packages

Some packages that we use in this worksheet:

>    restart: with(plots):

Warning, the name changecoords has been redefined

Introduction

In this worksheet we define a number of Maple  commands that make it easier to compute the Fourier coefficients and Fourier series for a given function and plot different Fourier polynomials (i.e., finite approximations to Fourier Series). We illustrate how to use these commands (and also the Fourier series themselves) by a number of examples.   

Definitions

>    assume(n,integer);
assume(m,integer);

Shorthand notation for basic functions

>    s:=(x,n)->sin(n*Pi*x/L):s(x,n);
c:=(x,n)->cos(n*Pi*x/L):c(x,n);

sin(n*Pi*x/L)

cos(n*Pi*x/L)

Fourier sine coefficients for f(x)    on the interval [0, L]  

>    B:=proc(expr,var,n)
        simplify(int(expr*s(var,n),var=0..L)/int(s(var,n)*s(var,n),var=0..L));
end proc:B(f(x),x,n);

2/L*int(f(x)*sin(n*Pi*x/L),x = 0 .. L)

Fourier cosine coefficients for f(x)    on the interval [0, L]    (note that the formulas are different for n = 0    and 0 < n   )

>    A:=proc(expr,var,n)
        simplify(int(expr*c(var,n),var=0..L)/int(c(var,n)*c(var,n),var=0..L));
end proc:A(f(x),x,0);A(f(x),x,n);

1/L*int(f(x),x = 0 .. L)

2/L*int(f(x)*cos(n*Pi*x/L),x = 0 .. L)

Full Fourier coefficients for f(x)    on the interval [-L, L]  

>    Bf:=proc(expr,var,n)
        simplify(int(expr*s(var,n),var=-L..L)/int(s(var,n)*s(var,n),var=-L..L));
end proc:Bf(f(x),x,n);
Af:=proc(expr,var,n)
        simplify(int(expr*c(var,n),var=-L..L)/int(c(var,n)*c(var,n),var=-L..L));
end proc:Af(f(x),x,0);Af(f(x),x,n);

1/L*int(f(x)*sin(n*Pi*x/L),x = -L .. L)

1/2*1/L*int(f(x),x = -L .. L)

1/L*int(f(x)*cos(n*Pi*x/L),x = -L .. L)

Fourier sine series and Fourier sine polynomial  for f(x)  on the interval [0, L]   (The subtle difference here is that sometimes series (that uses sum ) has troubles with division by zero. The polynomial (that uses add ) does not have this problem, but on the other hand can not evaluate symbolic sums).

>    FPs:=proc(expr,var,n)
        add(B(expr,var,m)*s(var,m),m=1..n);
end proc:
FSs:=proc(expr,var,n)
        sum(B(expr,var,m)*s(var,m),m=1..n);
end proc:FSs(f(x),x,infinity);

sum(2/L*sin(m*Pi*x/L)*int(f(x)*sin(m*Pi*x/L),x = 0 .. L),m = 1 .. infinity)

Fourier cosine series and Fourier cosine polynomial for f(x)  on the interval [0, L]

>    FPc:=proc(expr,var,n)
        A(expr,var,0)+add(A(expr,var,m)*c(var,m),m=1..n);
end proc:
FSc:=proc(expr,var,n)
        A(expr,var,0)+sum(A(expr,var,m)*c(var,m),m=1..n);
end proc:FSc(f(x),x,infinity);

1/L*int(f(x),x = 0 .. L)+sum(2/L*cos(m*Pi*x/L)*int(f(x)*cos(m*Pi*x/L),x = 0 .. L),m = 1 .. infinity)

Full Fourier series and full Fourier polynomial for f(x)  on the interval [-L, L]

>    FP:=proc(expr,var,n)
        Af(expr,var,0)+add(Af(expr,var,m)*c(var,m)+Bf(expr,var,m)*s(var,m),m=1..n);
end proc:
FS:=proc(expr,var,n)
        Af(expr,var,0)+sum(Af(expr,var,m)*c(var,m)+Bf(expr,var,m)*s(var,m),m=1..n);
end proc:FS(f(x),x,infinity);

1/2*1/L*int(f(x),x = -L .. L)+sum(1/L*cos(m*Pi*x/L)*int(f(x)*cos(m*Pi*x/L),x = -L .. L)+1/L*sin(m*Pi*x/L)*int(f(x)*sin(m*Pi*x/L),x = -L .. L),m = 1 .. infinity)

Odd extension of expr  from the interval [0, L]  to the whole real line

>    oddext:=proc(expr,var,L)
   local x;
   x:=var - floor((var+L)/(2*L))*2*L;
   unapply(signum(x)*unapply(expr,var)(abs(x)),var)
end proc:

Even extension of expr  from the interval [0, L]  to the whole real line

>    evenext:=proc(expr,var,L)
   local x;
   x:=var - floor((var+L)/(2*L))*2*L;
   unapply(unapply(expr,var)(abs(x)),var)
end proc:

Periodic extension of expr  from the interval [-L, L]  to the whole real line

>    pext:=proc(expr,var,L)
   unapply(unapply(expr,var)(var - floor((var+L)/(2*L))*2*L),var)
end proc:

>   

Example 1: f(x) = 1

A constant function:

>    f:=x->1: f(x);

1

>    B[n]=B(f(x),x,n);
seq(B[n]=B(f(x),x,n),n=1..10);
FSs(f(x),x,infinity);FPs(f(x),x,10);

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

B[1] = 4/Pi, B[2] = 0, B[3] = 4/3/Pi, B[4] = 0, B[5] = 4/5/Pi, B[6] = 0, B[7] = 4/7/Pi, B[8] = 0, B[9] = 4/9/Pi, B[10] = 0

sum(-2*(-1+(-1)^m)/m/Pi*sin(m*Pi*x/L),m = 1 .. infinity)

4/Pi*sin(Pi*x/L)+4/3*1/Pi*sin(3*Pi*x/L)+4/5*1/Pi*sin(5*Pi*x/L)+4/7*1/Pi*sin(7*Pi*x/L)+4/9*1/Pi*sin(9*Pi*x/L)

>    A[n]=A(f(x),x,n);
seq(A[n]=A(f(x),x,n),n=0..10);
FSc(f(x),x,infinity);FPc(f(x),x,10);

A[n] = 0

A[0] = 1, A[1] = 0, A[2] = 0, A[3] = 0, A[4] = 0, A[5] = 0, A[6] = 0, A[7] = 0, A[8] = 0, A[9] = 0, A[10] = 0

1

1

>    A[n]=Af(f(x),x,n);B[n]=Bf(f(x),x,n);
seq(A[n]=Af(f(x),x,n),n=0..10);
seq(B[n]=Bf(f(x),x,n),n=1..10);
FS(f(x),x,infinity);FP(f(x),x,10);

A[n] = 0

B[n] = 0

A[0] = 1, A[1] = 0, A[2] = 0, A[3] = 0, A[4] = 0, A[5] = 0, A[6] = 0, A[7] = 0, A[8] = 0, A[9] = 0, A[10] = 0

B[1] = 0, B[2] = 0, B[3] = 0, B[4] = 0, B[5] = 0, B[6] = 0, B[7] = 0, B[8] = 0, B[9] = 0, B[10] = 0

1

1

>    L:=1;

L := 1

Fourier sine series differs from the function f(x) .

>    display(
[plot(f(x),x=-3*L..3*L,color=red,thickness=2,title=sprintf("Function f(x)=%a and ...",f(x))),
seq(plot([f(x),FPs(f(x),x,5*i+1)],x=-3*L..3*L,color=[red,blue],thickness=2,numpoints=1000,
title=sprintf("... and its Fourier sine series with %d terms and ...",5*i+1)),i=0..3)
]
,scaling=constrained,view=[-3*L..3*L,-3*L..3*L],insequence=true);

[Maple Plot]

Since 1  belongs to the basis of the cosine Fourier family and the full Fourier family, its series are given by just the first term, and so the approximation is exact:

>    display(
[plot(f(x),x=-3*L..3*L,color=red,thickness=2,title=sprintf("Function f(x)=%a and ...",f(x))),
seq(plot([f(x),FPc(f(x),x,5*i+1)],x=-3*L..3*L,color=[red,blue],thickness=2,numpoints=1000,
title=sprintf("... and its Fourier cosine series with %d terms and ...",5*i+1)),i=0..3)
]
,scaling=constrained,view=[-3*L..3*L,-3*L..3*L],insequence=true);

[Maple Plot]

>    display(
[plot(f(x),x=-3*L..3*L,color=red,thickness=2,title=sprintf("Function f(x)=%a and ...",f(x))),
seq(plot([f(x),FP(f(x),x,5*i+1)],x=-3*L..3*L,color=[red,blue],thickness=2,numpoints=1000,
title=sprintf("... and its Fourier series with %d terms and ...",5*i+1)),i=0..3)
]
,scaling=constrained,view=[-3*L..3*L,-3*L..3*L],insequence=true);

[Maple Plot]

Fourier sine series converges to an odd periodic extension of f(x) .

>    plot([f(x),FPs(f(x),x,7),oddext(f(x),x,L)(x)],x=-3*L..3*L,color=[red,blue,violet],thickness=2,numpoints=1000,
title=sprintf("%a, its Fourier sine series with %d terms and its odd periodic extension",f(x),7),scaling=constrained,view=[-3*L..3*L,-3*L..3*L]);

[Maple Plot]

Fourier cosine series converges to an even periodic extension of f(x) .

>    plot([f(x),FPc(f(x),x,7),evenext(f(x),x,L)(x)],x=-3*L..3*L,color=[red,blue,violet],thickness=2,numpoints=1000,
title=sprintf("%a, its Fourier cosine series with %d terms and its even periodic extension",f(x),7),scaling=constrained,view=[-3*L..3*L,-3*L..3*L]);

[Maple Plot]

Full Fourier series converges to a periodic extension  of f(x) .

>    plot([f(x),FP(f(x),x,7),pext(f(x),x,L)(x)],x=-3*L..3*L,color=[red,blue,violet],thickness=2,numpoints=1000,
title=sprintf("%a, its Fourier series with %d terms and its periodic extension",f(x),7),scaling=constrained,view=[-3*L..3*L,-3*L..3*L]);

[Maple Plot]

Clean-up:

>    f:='f':L:='L':

>   

Example 2: f(x) = x

An odd function:

>    f:=x->x: f(x);

x

>    B[n]=B(f(x),x,n);
seq(B[n]=B(f(x),x,n),n=1..10);
FSs(f(x),x,infinity);FPs(f(x),x,10);

B[n] = 2*(-1)^(1+n)/n/Pi*L

B[1] = 2/Pi*L, B[2] = -1/Pi*L, B[3] = 2/3/Pi*L, B[4] = -1/2/Pi*L, B[5] = 2/5/Pi*L, B[6] = -1/3/Pi*L, B[7] = 2/7/Pi*L, B[8] = -1/4/Pi*L, B[9] = 2/9/Pi*L, B[10] = -1/5/Pi*L

sum(2*(-1)^(m+1)/m/Pi*L*sin(m*Pi*x/L),m = 1 .. infinity)

2*sin(Pi*x/L)/Pi*L-sin(2*Pi*x/L)/Pi*L+2/3*sin(3*Pi*x/L)/Pi*L-1/2*sin(4*Pi*x/L)/Pi*L+2/5*sin(5*Pi*x/L)/Pi*L-1/3*sin(6*Pi*x/L)/Pi*L+2/7*sin(7*Pi*x/L)/Pi*L-1/4*sin(8*Pi*x/L)/Pi*L+2/9*sin(9*Pi*x/L)/Pi*L-1/...

>    A[n]=A(f(x),x,n);
seq(A[n]=A(f(x),x,n),n=0..10);
FSc(f(x),x,infinity);FPc(f(x),x,10);

A[n] = 2*L*(-1+(-1)^n)/n^2/Pi^2

A[0] = 1/2*L, A[1] = -4*L/Pi^2, A[2] = 0, A[3] = -4/9*L/Pi^2, A[4] = 0, A[5] = -4/25*L/Pi^2, A[6] = 0, A[7] = -4/49*L/Pi^2, A[8] = 0, A[9] = -4/81*L/Pi^2, A[10] = 0

1/2*L+sum(2*L*(-1+(-1)^m)/m^2/Pi^2*cos(m*Pi*x/L),m = 1 .. infinity)

1/2*L-4*L/Pi^2*cos(Pi*x/L)-4/9*L/Pi^2*cos(3*Pi*x/L)-4/25*L/Pi^2*cos(5*Pi*x/L)-4/49*L/Pi^2*cos(7*Pi*x/L)-4/81*L/Pi^2*cos(9*Pi*x/L)

Since f(x)  is odd , its even Fourier coefficients (i.e., A[n] ) are zero.

>    A[n]=Af(f(x),x,n);B[n]=Bf(f(x),x,n);
seq(A[n]=Af(f(x),x,n),n=0..10);
seq(B[n]=Bf(f(x),x,n),n=1..10);
FS(f(x),x,infinity);FP(f(x),x,10);

A[n] = 0

B[n] = 2*(-1)^(1+n)/n/Pi*L

A[0] = 0, A[1] = 0, A[2] = 0, A[3] = 0, A[4] = 0, A[5] = 0, A[6] = 0, A[7] = 0, A[8] = 0, A[9] = 0, A[10] = 0

B[1] = 2/Pi*L, B[2] = -1/Pi*L, B[3] = 2/3/Pi*L, B[4] = -1/2/Pi*L, B[5] = 2/5/Pi*L, B[6] = -1/3/Pi*L, B[7] = 2/7/Pi*L, B[8] = -1/4/Pi*L, B[9] = 2/9/Pi*L, B[10] = -1/5/Pi*L

sum(2*(-1)^(m+1)/m/Pi*L*sin(m*Pi*x/L),m = 1 .. infinity)

2*sin(Pi*x/L)/Pi*L-sin(2*Pi*x/L)/Pi*L+2/3*sin(3*Pi*x/L)/Pi*L-1/2*sin(4*Pi*x/L)/Pi*L+2/5*sin(5*Pi*x/L)/Pi*L-1/3*sin(6*Pi*x/L)/Pi*L+2/7*sin(7*Pi*x/L)/Pi*L-1/4*sin(8*Pi*x/L)/Pi*L+2/9*sin(9*Pi*x/L)/Pi*L-1/...

>    L:=1;

L := 1

>    display(
[plot(f(x),x=-3*L..3*L,color=red,thickness=2,title=sprintf("Function f(x)=%a and ...",f(x))),
seq(plot([f(x),FPs(f(x),x,5*i+1)],x=-3*L..3*L,color=[red,blue],thickness=2,numpoints=1000,
title=sprintf("... and its Fourier sine series with %d terms and ...",5*i+1)),i=0..3)
]
,scaling=constrained,view=[-3*L..3*L,-3*L..3*L],insequence=true);

[Maple Plot]

>    display(
[plot(f(x),x=-3*L..3*L,color=red,thickness=2,title=sprintf("Function f(x)=%a and ...",f(x))),
seq(plot([f(x),FPc(f(x),x,5*i+1)],x=-3*L..3*L,color=[red,blue],thickness=2,numpoints=1000,
title=sprintf("... and its Fourier cosine series with %d terms and ...",5*i+1)),i=0..3)
]
,scaling=constrained,view=[-3*L..3*L,-3*L..3*L],insequence=true);

[Maple Plot]

>    display(
[plot(f(x),x=-3*L..3*L,color=red,thickness=2,title=sprintf("Function f(x)=%a and ...",f(x))),
seq(plot([f(x),FP(f(x),x,5*i+1)],x=-3*L..3*L,color=[red,blue],thickness=2,numpoints=1000,
title=sprintf("... and its Fourier series with %d terms and ...",5*i+1)),i=0..3)
]
,scaling=constrained,view=[-3*L..3*L,-3*L..3*L],insequence=true);

[Maple Plot]

>    plot([f(x),FPs(f(x),x,7),oddext(f(x),x,L)(x)],x=-3*L..3*L,color=[red,blue,violet],thickness=2,numpoints=1000,
title=sprintf("%a, its Fourier sine series with %d terms and its odd periodic extension",f(x),7),scaling=constrained,view=[-3*L..3*L,-3*L..3*L]);

[Maple Plot]

>    plot([f(x),FPc(f(x),x,7),evenext(f(x),x,L)(x)],x=-3*L..3*L,color=[red,blue,violet],thickness=2,numpoints=1000,
title=sprintf("%a, its Fourier cosine series with %d terms and its even periodic extension",f(x),7),scaling=constrained,view=[-3*L..3*L,-3*L..3*L]);

[Maple Plot]

>    plot([f(x),FP(f(x),x,7),pext(f(x),x,L)(x)],x=-3*L..3*L,color=[red,blue,violet],thickness=2,numpoints=1000,
title=sprintf("%a, its Fourier series with %d terms and its periodic extension",f(x),7),scaling=constrained,view=[-3*L..3*L,-3*L..3*L]);

[Maple Plot]

Clean-up:

>    f:='f':L:='L':

>   

Example 3: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2...

>    A[n]=A(f(x),x,n);
seq(A[n]=A(f(x),x,n),n=0..10);
FSc(f(x),x,infinity);FPc(f(x),x,10);

A[n] = 4*(-1)^n*L^2/n^2/Pi^2

A[0] = 1/3*L^2, A[1] = -4/Pi^2*L^2, A[2] = 1/Pi^2*L^2, A[3] = -4/9/Pi^2*L^2, A[4] = 1/4/Pi^2*L^2, A[5] = -4/25/Pi^2*L^2, A[6] = 1/9/Pi^2*L^2, A[7] = -4/49/Pi^2*L^2, A[8] = 1/16/Pi^2*L^2, A[9] = -4/81/P...

1/3*L^2+sum(4*(-1)^m*L^2/m^2/Pi^2*cos(m*Pi*x/L),m = 1 .. infinity)

1/3*L^2-4*L^2/Pi^2*cos(Pi*x/L)+1/Pi^2*L^2*cos(2*Pi*x/L)-4/9*1/Pi^2*L^2*cos(3*Pi*x/L)+1/4*1/Pi^2*L^2*cos(4*Pi*x/L)-4/25*1/Pi^2*L^2*cos(5*Pi*x/L)+1/9*1/Pi^2*L^2*cos(6*Pi*x/L)-4/49*1/Pi^2*L^2*cos(7*Pi*x/L...
1/3*L^2-4*L^2/Pi^2*cos(Pi*x/L)+1/Pi^2*L^2*cos(2*Pi*x/L)-4/9*1/Pi^2*L^2*cos(3*Pi*x/L)+1/4*1/Pi^2*L^2*cos(4*Pi*x/L)-4/25*1/Pi^2*L^2*cos(5*Pi*x/L)+1/9*1/Pi^2*L^2*cos(6*Pi*x/L)-4/49*1/Pi^2*L^2*cos(7*Pi*x/L...

Since the function is even , its odd  coefficients are zero.

>    A[n]=Af(f(x),x,n);B[n]=Bf(f(x),x,n);
seq(A[n]=Af(f(x),x,n),n=0..10);
seq(B[n]=Bf(f(x),x,n),n=1..10);
FS(f(x),x,infinity);FP(f(x),x,10);

A[n] = 4*(-1)^n*L^2/n^2/Pi^2

B[n] = 0

A[0] = 1/3*L^2, A[1] = -4/Pi^2*L^2, A[2] = 1/Pi^2*L^2, A[3] = -4/9/Pi^2*L^2, A[4] = 1/4/Pi^2*L^2, A[5] = -4/25/Pi^2*L^2, A[6] = 1/9/Pi^2*L^2, A[7] = -4/49/Pi^2*L^2, A[8] = 1/16/Pi^2*L^2, A[9] = -4/81/P...

B[1] = 0, B[2] = 0, B[3] = 0, B[4] = 0, B[5] = 0, B[6] = 0, B[7] = 0, B[8] = 0, B[9] = 0, B[10] = 0

1/3*L^2+sum(4*(-1)^m*L^2/m^2/Pi^2*cos(m*Pi*x/L),m = 1 .. infinity)

1/3*L^2-4*L^2/Pi^2*cos(Pi*x/L)+1/Pi^2*L^2*cos(2*Pi*x/L)-4/9*1/Pi^2*L^2*cos(3*Pi*x/L)+1/4*1/Pi^2*L^2*cos(4*Pi*x/L)-4/25*1/Pi^2*L^2*cos(5*Pi*x/L)+1/9*1/Pi^2*L^2*cos(6*Pi*x/L)-4/49*1/Pi^2*L^2*cos(7*Pi*x/L...
1/3*L^2-4*L^2/Pi^2*cos(Pi*x/L)+1/Pi^2*L^2*cos(2*Pi*x/L)-4/9*1/Pi^2*L^2*cos(3*Pi*x/L)+1/4*1/Pi^2*L^2*cos(4*Pi*x/L)-4/25*1/Pi^2*L^2*cos(5*Pi*x/L)+1/9*1/Pi^2*L^2*cos(6*Pi*x/L)-4/49*1/Pi^2*L^2*cos(7*Pi*x/L...

>    L:=1;

L := 1

>    display(
[plot(f(x),x=-3*L..3*L,color=red,thickness=2,title=sprintf("Function f(x)=%a and ...",f(x))),
seq(plot([f(x),FPs(f(x),x,5*i+1)],x=-3*L..3*L,color=[red,blue],thickness=2,numpoints=1000,
title=sprintf("... and its Fourier sine series with %d terms and ...",5*i+1)),i=0..3)
]
,scaling=constrained,view=[-3*L..3*L,-3*L..3*L],insequence=true);

[Maple Plot]

>    display(
[plot(f(x),x=-3*L..3*L,color=red,thickness=2,title=sprintf("Function f(x)=%a and ...",f(x))),
seq(plot([f(x),FPc(f(x),x,5*i+1)],x=-3*L..3*L,color=[red,blue],thickness=2,numpoints=1000,
title=sprintf("... and its Fourier cosine series with %d terms and ...",5*i+1)),i=0..3)
]
,scaling=constrained,view=[-3*L..3*L,-3*L..3*L],insequence=true);

[Maple Plot]

>    display(
[plot(f(x),x=-3*L..3*L,color=red,thickness=2,title=sprintf("Function f(x)=%a and ...",f(x))),
seq(plot([f(x),FP(f(x),x,5*i+1)],x=-3*L..3*L,color=[red,blue],thickness=2,numpoints=1000,
title=sprintf("... and its Fourier series with %d terms and ...",5*i+1)),i=0..3)
]
,scaling=constrained,view=[-3*L..3*L,-3*L..3*L],insequence=true);

[Maple Plot]

>    plot([f(x),FPs(f(x),x,7),oddext(f(x),x,L)(x)],x=-3*L..3*L,color=[red,blue,violet],thickness=2,numpoints=1000,
title=sprintf("%a, its Fourier sine series with %d terms and its odd periodic extension",f(x),7),scaling=constrained,view=[-3*L..3*L,-3*L..3*L]);

[Maple Plot]

>    plot([f(x),FPc(f(x),x,7),evenext(f(x),x,L)(x)],x=-3*L..3*L,color=[red,blue,violet],thickness=2,numpoints=1000,
title=sprintf("%a, its Fourier cosine series with %d terms and its even periodic extension",f(x),7),scaling=constrained,view=[-3*L..3*L,-3*L..3*L]);

[Maple Plot]

>    plot([f(x),FP(f(x),x,7),pext(f(x),x,L)(x)],x=-3*L..3*L,color=[red,blue,violet],thickness=2,numpoints=1000,
title=sprintf("%a, its Fourier series with %d terms and its periodic extension",f(x),7),scaling=constrained,view=[-3*L..3*L,-3*L..3*L]);

[Maple Plot]

Clean-up:

>    f:='f':L:='L':

>   

Example 4: f(x) = x^2-x

>    f:=x->x^2-x: f(x);

x^2-x

>    B[n]=B(f(x),x,n);
seq(B[n]=B(f(x),x,n),n=1..10);
FSs(f(x),x,infinity);FPs(f(x),x,10);

B[n] = -2*L*(2*L+2*(-1)^(1+n)*L+n^2*Pi^2*(-1)^n*L-n^2*Pi^2*(-1)^n)/n^3/Pi^3

B[1] = 2*L*(-4*L+Pi^2*L-Pi^2)/Pi^3, B[2] = -L/Pi*(L-1), B[3] = 2/27*L*(-4*L+9*Pi^2*L-9*Pi^2)/Pi^3, B[4] =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*(L-1)/Pi^2, A[6] = 1/9/Pi^2*L^2, A[7] = -4/49*L*(L-1)/Pi^2, A[8] = 1/16/Pi...

1/6*L*(2*L-3)+sum(2*L*(1+2*(-1)^m*L-(-1)^m)/m^2/Pi^2*cos(m*Pi*x/L),m = 1 .. infinity)

1/6*L*(2*L-3)-4*L*(L-1)/Pi^2*cos(Pi*x/L)+1/Pi^2*L^2*cos(2*Pi*x/L)-4/9*L*(L-1)/Pi^2*cos(3*Pi*x/L)+1/4*1/Pi^2*L^2*cos(4*Pi*x/L)-4/25*L*(L-1)/Pi^2*cos(5*Pi*x/L)+1/9*1/Pi^2*L^2*cos(6*Pi*x/L)-4/49*L*(L-1)/P...
1/6*L*(2*L-3)-4*L*(L-1)/Pi^2*cos(Pi*x/L)+1/Pi^2*L^2*cos(2*Pi*x/L)-4/9*L*(L-1)/Pi^2*cos(3*Pi*x/L)+1/4*1/Pi^2*L^2*cos(4*Pi*x/L)-4/25*L*(L-1)/Pi^2*cos(5*Pi*x/L)+1/9*1/Pi^2*L^2*cos(6*Pi*x/L)-4/49*L*(L-1)/P...

This function is neither even nor odd, and so all of its Fourier coefficients are non-zero:

>    A[n]=Af(f(x),x,n);B[n]=Bf(f(x),x,n);
seq(A[n]=Af(f(x),x,n),n=0..10);
seq(B[n]=Bf(f(x),x,n),n=1..10);
FS(f(x),x,infinity);FP(f(x),x,10);

A[n] = 4*(-1)^n*L^2/n^2/Pi^2

B[n] = 2*(-1)^n/n/Pi*L

A[0] = 1/3*L^2, A[1] = -4/Pi^2*L^2, A[2] = 1/Pi^2*L^2, A[3] = -4/9/Pi^2*L^2, A[4] = 1/4/Pi^2*L^2, A[5] = -4/25/Pi^2*L^2, A[6] = 1/9/Pi^2*L^2, A[7] = -4/49/Pi^2*L^2, A[8] = 1/16/Pi^2*L^2, A[9] = -4/81/P...

B[1] = -2/Pi*L, B[2] = 1/Pi*L, B[3] = -2/3/Pi*L, B[4] = 1/2/Pi*L, B[5] = -2/5/Pi*L, B[6] = 1/3/Pi*L, B[7] = -2/7/Pi*L, B[8] = 1/4/Pi*L, B[9] = -2/9/Pi*L, B[10] = 1/5/Pi*L

1/3*L^2+sum(4*(-1)^m*L^2/m^2/Pi^2*cos(m*Pi*x/L)+2*sin(m*Pi*x/L)/m/Pi*L*(-1)^m,m = 1 .. infinity)

1/3*L^2-4*L^2/Pi^2*cos(Pi*x/L)-2*sin(Pi*x/L)/Pi*L+1/Pi^2*L^2*cos(2*Pi*x/L)+sin(2*Pi*x/L)/Pi*L-4/9*1/Pi^2*L^2*cos(3*Pi*x/L)-2/3*sin(3*Pi*x/L)/Pi*L+1/4*1/Pi^2*L^2*cos(4*Pi*x/L)+1/2*sin(4*Pi*x/L)/Pi*L-4/2...
1/3*L^2-4*L^2/Pi^2*cos(Pi*x/L)-2*sin(Pi*x/L)/Pi*L+1/Pi^2*L^2*cos(2*Pi*x/L)+sin(2*Pi*x/L)/Pi*L-4/9*1/Pi^2*L^2*cos(3*Pi*x/L)-2/3*sin(3*Pi*x/L)/Pi*L+1/4*1/Pi^2*L^2*cos(4*Pi*x/L)+1/2*sin(4*Pi*x/L)/Pi*L-4/2...
1/3*L^2-4*L^2/Pi^2*cos(Pi*x/L)-2*sin(Pi*x/L)/Pi*L+1/Pi^2*L^2*cos(2*Pi*x/L)+sin(2*Pi*x/L)/Pi*L-4/9*1/Pi^2*L^2*cos(3*Pi*x/L)-2/3*sin(3*Pi*x/L)/Pi*L+1/4*1/Pi^2*L^2*cos(4*Pi*x/L)+1/2*sin(4*Pi*x/L)/Pi*L-4/2...

>    L:=1;

L := 1

>    display(
[plot(f(x),x=-3*L..3*L,color=red,thickness=2,title=sprintf("Function f(x)=%a and ...",f(x))),
seq(plot([f(x),FPs(f(x),x,5*i+1)],x=-3*L..3*L,color=[red,blue],thickness=2,numpoints=1000,
title=sprintf("... and its Fourier sine series with %d terms and ...",5*i+1)),i=0..3)
]
,scaling=constrained,view=[-3*L..3*L,-3*L..3*L],insequence=true);

[Maple Plot]

>    display(
[plot(f(x),x=-3*L..3*L,color=red,thickness=2,title=sprintf("Function f(x)=%a and ...",f(x))),
seq(plot([f(x),FPc(f(x),x,5*i+1)],x=-3*L..3*L,color=[red,blue],thickness=2,numpoints=1000,
title=sprintf("... and its Fourier cosine series with %d terms and ...",5*i+1)),i=0..3)
]
,scaling=constrained,view=[-3*L..3*L,-3*L..3*L],insequence=true);

[Maple Plot]

>    display(
[plot(f(x),x=-3*L..3*L,color=red,thickness=2,title=sprintf("Function f(x)=%a and ...",f(x))),
seq(plot([f(x),FP(f(x),x,5*i+1)],x=-3*L..3*L,color=[red,blue],thickness=2,numpoints=1000,
title=sprintf("... and its Fourier series with %d terms and ...",5*i+1)),i=0..3)
]
,scaling=constrained,view=[-3*L..3*L,-3*L..3*L],insequence=true);

[Maple Plot]

>    plot([f(x),FPs(f(x),x,7),oddext(f(x),x,L)(x)],x=-3*L..3*L,color=[red,blue,violet],thickness=2,numpoints=1000,
title=sprintf("%a, its Fourier sine series with %d terms and its odd periodic extension",f(x),7),scaling=constrained,view=[-3*L..3*L,-3*L..3*L]);

[Maple Plot]

>    plot([f(x),FPc(f(x),x,7),evenext(f(x),x,L)(x)],x=-3*L..3*L,color=[red,blue,violet],thickness=2,numpoints=1000,
title=sprintf("%a, its Fourier cosine series with %d terms and its even periodic extension",f(x),7),scaling=constrained,view=[-3*L..3*L,-3*L..3*L]);

[Maple Plot]

>    plot([f(x),FP(f(x),x,7),pext(f(x),x,L)(x)],x=-3*L..3*L,color=[red,blue,violet],thickness=2,numpoints=1000,
title=sprintf("%a, its Fourier series with %d terms and its periodic extension",f(x),7),scaling=constrained,view=[-3*L..3*L,-3*L..3*L]);

[Maple Plot]

Clean-up:

>    f:='f':L:='L':

>   

Example 5: f(x) = cos(Pi*x/L)

In this example f(x) is a basic function of the cosine   Fourier  family and the full Fourier  family

>    f:=x->cos(Pi*x/L): f(x);

cos(Pi*x/L)

>    B[n]=B(f(x),x,n);
seq(B[n]=B(f(x),x,n),n=1..10);
FSs(f(x),x,infinity);FPs(f(x),x,10);

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

B[1] = 0, B[2] = 8/3/Pi, B[3] = 0, B[4] = 16/15/Pi, B[5] = 0, B[6] = 24/35/Pi, B[7] = 0, B[8] = 32/63/Pi, B[9] = 0, B[10] = 40/99/Pi

sum(2*m*(1+(-1)^m)/Pi/(m^2-1)*sin(m*Pi*x/L),m = 1 .. infinity)

8/3*1/Pi*sin(2*Pi*x/L)+16/15*1/Pi*sin(4*Pi*x/L)+24/35*1/Pi*sin(6*Pi*x/L)+32/63*1/Pi*sin(8*Pi*x/L)+40/99*1/Pi*sin(10*Pi*x/L)

>    A[n]=A(f(x),x,n);
seq(A[n]=A(f(x),x,n),n=0..10);
FSc(f(x),x,infinity);FPc(f(x),x,10);

A[n] = 0

A[0] = 0, A[1] = 1, A[2] = 0, A[3] = 0, A[4] = 0, A[5] = 0, A[6] = 0, A[7] = 0, A[8] = 0, A[9] = 0, A[10] = 0

0

cos(Pi*x/L)

>    A[n]=Af(f(x),x,n);B[n]=Bf(f(x),x,n);
seq(A[n]=Af(f(x),x,n),n=0..10);
seq(B[n]=Bf(f(x),x,n),n=1..10);
FS(f(x),x,infinity);FP(f(x),x,10);

A[n] = 0

B[n] = 0

A[0] = 0, A[1] = 1, A[2] = 0, A[3] = 0, A[4] = 0, A[5] = 0, A[6] = 0, A[7] = 0, A[8] = 0, A[9] = 0, A[10] = 0

B[1] = 0, B[2] = 0, B[3] = 0, B[4] = 0, B[5] = 0, B[6] = 0, B[7] = 0, B[8] = 0, B[9] = 0, B[10] = 0

0

cos(Pi*x/L)

>    L:=1;

L := 1

>    display(
[plot(f(x),x=-3*L..3*L,color=red,thickness=2,title=sprintf("Function f(x)=%a and ...",f(x))),
seq(plot([f(x),FPs(f(x),x,5*i+1)],x=-3*L..3*L,color=[red,blue],thickness=2,numpoints=1000,
title=sprintf("... and its Fourier sine series with %d terms and ...",5*i+1)),i=0..3)
]
,scaling=constrained,view=[-3*L..3*L,-3*L..3*L],insequence=true);

[Maple Plot]

>    display(
[plot(f(x),x=-3*L..3*L,color=red,thickness=2,title=sprintf("Function f(x)=%a and ...",f(x))),
seq(plot([f(x),FPc(f(x),x,5*i+1)],x=-3*L..3*L,color=[red,blue],thickness=2,numpoints=1000,
title=sprintf("... and its Fourier cosine series with %d terms and ...",5*i+1)),i=0..3)
]
,scaling=constrained,view=[-3*L..3*L,-3*L..3*L],insequence=true);

[Maple Plot]

>    display(
[plot(f(x),x=-3*L..3*L,color=red,thickness=2,title=sprintf("Function f(x)=%a and ...",f(x))),
seq(plot([f(x),FP(f(x),x,5*i+1)],x=-3*L..3*L,color=[red,blue],thickness=2,numpoints=1000,
title=sprintf("... and its Fourier series with %d terms and ...",5*i+1)),i=0..3)
]
,scaling=constrained,view=[-3*L..3*L,-3*L..3*L],insequence=true);

[Maple Plot]

>    plot([f(x),FPs(f(x),x,7),oddext(f(x),x,L)(x)],x=-3*L..3*L,color=[red,blue,violet],thickness=2,numpoints=1000,
title=sprintf("%a, its Fourier sine series with %d terms and its odd periodic extension",f(x),7),scaling=constrained,view=[-3*L..3*L,-3*L..3*L]);

[Maple Plot]

>    plot([f(x),FPc(f(x),x,7),evenext(f(x),x,L)(x)],x=-3*L..3*L,color=[red,blue,violet],thickness=2,numpoints=1000,
title=sprintf("%a, its Fourier cosine series with %d terms and its even periodic extension",f(x),7),scaling=constrained,view=[-3*L..3*L,-3*L..3*L]);

[Maple Plot]

>    plot([f(x),FP(f(x),x,7),pext(f(x),x,L)(x)],x=-3*L..3*L,color=[red,blue,violet],thickness=2,numpoints=1000,
title=sprintf("%a, its Fourier series with %d terms and its periodic extension",f(x),7),scaling=constrained,view=[-3*L..3*L,-3*L..3*L]);

[Maple Plot]

Clean-up:

>    f:='f':L:='L':

>   

Example 6: f(x) = piecewise(x < 0,0,x < L/2,x,x < L,1,0)

>    assume(L>0);

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

PIECEWISE([0, x < 0],[x, x < 1/2*L],[1, x < L],[0, otherwise])

Since in this case it is hard to obtain general formulas, we'll take L = 1  from the very beginning:

>    L:=1;

L := 1

>    plot(f(x),x=0..L,color=red,thickness=2,scaling=constrained);

[Maple Plot]

>    B[n]=B(f(x),x,n);
seq(B[n]=B(f(x),x,n),n=1..10);
FSs(f(x),x,infinity);FPs(f(x),x,10);

B[n] = (2*(-1)^(1+n)*n*Pi+2*sin(1/2*n*Pi)+n*Pi*cos(1/2*n*Pi))/n^2/Pi^2

B[1] = 2*(Pi+1)/Pi^2, B[2] = -3/2/Pi, B[3] = 2/9*(3*Pi-1)/Pi^2, B[4] = -1/(4*Pi), B[5] = 2/25*(5*Pi+1)/Pi^2, B[6] = -1/(2*Pi), B[7] = 2/49*(7*Pi-1)/Pi^2, B[8] = -1/(8*Pi), B[9] = 2/81*(9*Pi+1)/Pi^2, B[...

sum(-(2*(-1)^m*m*Pi-2*sin(1/2*m*Pi)-m*Pi*cos(1/2*m*Pi))/m^2/Pi^2*sin(m*Pi*x),m = 1 .. infinity)

2*(Pi+1)/Pi^2*sin(Pi*x)-3/2*1/Pi*sin(2*Pi*x)+2/9*(3*Pi-1)/Pi^2*sin(3*Pi*x)-1/4*1/Pi*sin(4*Pi*x)+2/25*(5*Pi+1)/Pi^2*sin(5*Pi*x)-1/2*1/Pi*sin(6*Pi*x)+2/49*(7*Pi-1)/Pi^2*sin(7*Pi*x)-1/8*1/Pi*sin(8*Pi*x)+2...
2*(Pi+1)/Pi^2*sin(Pi*x)-3/2*1/Pi*sin(2*Pi*x)+2/9*(3*Pi-1)/Pi^2*sin(3*Pi*x)-1/4*1/Pi*sin(4*Pi*x)+2/25*(5*Pi+1)/Pi^2*sin(5*Pi*x)-1/2*1/Pi*sin(6*Pi*x)+2/49*(7*Pi-1)/Pi^2*sin(7*Pi*x)-1/8*1/Pi*sin(8*Pi*x)+2...

>    A[n]=A(f(x),x,n);
seq(A[n]=A(f(x),x,n),n=0..10);
FSc(f(x),x,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5*i+1)],x=-3*L..3*L,color=[red,blue],thickness=2,numpoints=1000,
title=sprintf("... and its Fourier sine series with %d terms and ...",5*i+1)),i=0..3)
]
,scaling=constrained,view=[-3*L..3*L,-3*L..3*L],insequence=true);

[Maple Plot]

>    display(
[plot(f(x),x=-3*L..3*L,color=red,thickness=2,title=sprintf("Function f(x)=%a and ...",f(x))),
seq(plot([f(x),FPc(f(x),x,5*i+1)],x=-3*L..3*L,color=[red,blue],thickness=2,numpoints=1000,
title=sprintf("... and its Fourier cosine series with %d terms and ...",5*i+1)),i=0..3)
]
,scaling=constrained,view=[-3*L..3*L,-3*L..3*L],insequence=true);

[Maple Plot]

>    display(
[plot(f(x),x=-3*L..3*L,color=red,thickness=2,title=sprintf("Function f(x)=%a and ...",f(x))),
seq(plot([f(x),FP(f(x),x,5*i+1)],x=-3*L..3*L,color=[red,blue],thickness=2,numpoints=1000,
title=sprintf("... and its Fourier series with %d terms and ...",5*i+1)),i=0..3)
]
,scaling=constrained,view=[-3*L..3*L,-3*L..3*L],insequence=true);

[Maple Plot]

>    plot([f(x),FPs(f(x),x,7),oddext(f(x),x,L)(x)],x=-3*L..3*L,color=[red,blue,violet],thickness=2,numpoints=1000,
title=sprintf("%a, its Fourier sine series with %d terms\n and its odd periodic extension",f(x),7),scaling=constrained,view=[-3*L..3*L,-3*L..3*L]);

[Maple Plot]

>    plot([f(x),FPc(f(x),x,7),evenext(f(x),x,L)(x)],x=-3*L..3*L,color=[red,blue,violet],thickness=2,numpoints=1000,
title=sprintf("%a, its Fourier cosine series with %d terms\n and its even periodic extension",f(x),7),scaling=constrained,view=[-3*L..3*L,-3*L..3*L]);

[Maple Plot]

>    plot([f(x),FP(f(x),x,7),pext(f(x),x,L)(x)],x=-3*L..3*L,color=[red,blue,violet],thickness=2,numpoints=1000,
title=sprintf("%a, its Fourier series with %d terms\n and its periodic extension",f(x),7),scaling=constrained,view=[-3*L..3*L,-3*L..3*L]);

[Maple Plot]

Clean-up:

>    f:='f':L:='L':

>   

>   

References

  • Richard Haberman, Elementary Applied Partial Differential Equations, 3rd edition, Prentice Hall

Disclaimer

"While every effort has been made to validate the solutions in this worksheet, Waterloo Maple Inc. and the contributors are not responsible for any errors contained and are not liable for any damages resulting from the use of this material."