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:
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);
|
Fourier sine coefficients for
on the interval
> |
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);
|
Fourier cosine coefficients for
on the interval
(note that the formulas are different for
and
)
> |
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);
|
Full Fourier coefficients for
on the interval
> |
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);
|
Fourier sine series and Fourier sine polynomial for
on the interval
(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);
|
Fourier cosine series and Fourier cosine polynomial for
on the interval
> |
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);
|
Full Fourier series and full Fourier polynomial for
on the interval
> |
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);
|
Odd extension of
expr
from the interval
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
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
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:
A constant function:
> |
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);
|
> |
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]=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);
|
Fourier sine series differs from the function
.
> |
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);
|
Since
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);
|
> |
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);
|
Fourier sine series converges to an
odd periodic extension
of
.
> |
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]);
|
Fourier cosine series converges to an even periodic extension of
.
> |
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]);
|
Full Fourier series converges to a
periodic extension
of
.
> |
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]);
|
Clean-up:
Example 2:
An odd function:
> |
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);
|
> |
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);
|
Since
is
odd
, its
even
Fourier coefficients (i.e.,
) 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);
|
> |
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);
|
> |
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);
|
> |
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);
|
> |
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]);
|
> |
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]);
|
> |
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]);
|
Clean-up:
Example 3:
An even function:
> |
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);
|
> |
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);
|
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);
|
> |
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);
|
> |
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);
|
> |
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);
|
> |
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]);
|
> |
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]);
|
> |
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]);
|
Clean-up:
Example 4:
> |
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);
|
> |
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);
|
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);
|
> |
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);
|
> |
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);
|
> |
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);
|
> |
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]);
|
> |
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]);
|
> |
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]);
|
Clean-up:
Example 5:
In this example
is a basic function of the
cosine
Fourier
family and the
full Fourier
family
> |
f:=x->cos(Pi*x/L): f(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);
|
> |
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]=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);
|
> |
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);
|
> |
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);
|
> |
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);
|
> |
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]);
|
> |
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]);
|
> |
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]);
|
Clean-up:
Example 6:
> |
f:=x->piecewise(x<0,0,x<L/2,x,x<L,1,0):f(x);
|
Since in this case it is hard to obtain general formulas, we'll take
from the very beginning:
> |
plot(f(x),x=0..L,color=red,thickness=2,scaling=constrained);
|
> |
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);
|
> |
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]=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);
|
> |
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);
|
> |
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);
|
> |
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);
|
> |
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]);
|
> |
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]);
|
> |
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]);
|
Clean-up:
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."