Application Center - Maplesoft

# FOURIER Series

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

FOURIER Series

Univ.-Prof. Dr.-Ing. habil. Josef  BETTEN

RWTH Aachen University

Templergraben 55

D-52056  A a c h e n ,  Germany

betten@mmw.rwth-aachen.de

Abstract

This worksheet is concerned with FOURIER series. Some examples are discussed

using MAPLE V, Release 10.

Keywords:  FOURIER expansion; odd and even functions;  HEAVISIDE function;

continuous functions with cusps; L-two norm

FOURIER Expansion

restart:                                                             FOURIER_series:=               a[0]/2+sum(a[k]*cos(k*x)+b[k]*sin(k*x),k=1..infinity);

 (1)

 > a[k]:=(1/Pi)*Int(f(x)*cos(k*x),x=-Pi..Pi); # k=0,1,2,3,...

 (2)

 > a[0]:=simplify(subs(k=0,%));

 (3)

 > b[k]:=(1/Pi)*Int(f(x)*sin(k*x),x=-Pi..Pi); # k=1,2,3,...

 (4)

ODD and Even Functions

 > odd_function:=f(x)=x;

 (5)

 > A[0]:=value(subs(f(x)=x,a[0]));

 (6)

 > A[k]:=value(subs(f(x)=x,a[k]));

 (7)

For odd functions the coefficients A[k],  k = 0,1,2.. are identical to zero.

 > B[k]:=value(subs(f(x)=x,b[k]));

 (8)

 > B[k]:=subs({sin(Pi*k)=0,cos(Pi*k)=(-1)^k},%);

 (9)

 > FOURIER_series[f(x)=x][k=4]:=sum(B[k]*sin(k*x),k=1..4);

 (10)

 > for i in [2,4,5] do FOURIER_series[f(x)=x][k=i]:=             subs(k=i,sum(B[k]*sin(k*x),k=1..i)) od;

 (11)

 (11)

 (11)

compact form:

 > y(x,n)[f(x)=x]:=Sum(B[k]*sin(k*x),k=1..n);

 (12)

 > y(x,4)[f(x)=x]:=value(subs(n=4,%));

 (13)

 > for i in [1,10,100] do       y(x,n=i):=2*subs(n=i,sum((-1)^(n-1)*sin(n*x)/n,n=1..i)) od:

 > plot({y(x,n=1),y(x,n=10),y(x,n=100)},x=-4*Pi..4*Pi,color=black,                             title="FOURIER-series with  n = [1, 10, 100]  for f(x) = x");

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

 (14)

 > A[0]:=value(subs(f(x)=x^2,a[0]));

 (15)

 > A[k]:=value(subs(f(x)=x^2,a[k]));

 (16)

 > A[k]:=subs({sin(Pi*k)=0,cos(Pi*k)=(-1)^k},%);

 (17)

 > B[k]:=value(subs(f(x)=x^2,b[k]));

 (18)

For even functions the coefficients  B[k] are identical to zero.

 > y(x,n)[f(x)=x^2]:=A[0]/2+Sum(A[k]*cos(k*x),k=1..n);

 (19)

 > y(x,4)[f(x)=x^2]:=value(subs(n=4,%));

 (20)

 > for i in [1,10,100] do       y(x,n=i):=Pi^2/3+subs(n=i,4*sum((-1)^n*cos(n*x)/n^2,                     n=1..i)) od:

 > plot({y(x,n=1),y(x,n=10),y(x,n=100)},                  x=-4*Pi..4*Pi,color=black,                                                 title="FOURIER-series # n = [1, 10, 100] for f(x) = x^2");

Function  f(x) = (x  - X)^2  in several ranges:

 > f(x)[-2*Pi]:=(x+2*Pi)^2;  x = [-3*Pi,  -Pi];

 (21)

 (21)

 > f(x)[0]:=x^2;   x = [-Pi,  Pi];

 (22)

 (22)

 > f(x)[2*Pi]:=(x-2*Pi)^2;   x = [Pi,  3*Pi];

 (23)

 (23)

 > alias(H=Heaviside,th=thickness,co=color):

 > p[1]:=plot(f(x)[-2*Pi],x=-3*Pi..-Pi,0..Pi^2,th=2,co=black):

 > p[2]:=plot(f(x)[0],x=-Pi..Pi,th=3,co=black):

 > p[3]:=plot(f(x)[2*Pi],x=Pi..3*Pi,th=2,co=black):

 > p[4]:=plot({Pi^2,Pi^2*H(x+3*Pi),Pi^2*H(x-3*Pi),   Pi^2*H(x+2*Pi),Pi^2*H(x-2*Pi)},                   x=-3.001*Pi..3.001*Pi,co=black,                                  title="Quadratic functions with the period  2*Pi"):

 > plots[display]({seq(p[k],k=1..4)});

 (24)

 > A[0]:=value(subs(f(x)=q,a[0]));

 (25)

 > A[k]:=value(subs(f(x)=q,a[k]));

 (26)

 > limit_value:=Limit(A[k],k=0)=limit(%,k=0);

 (27)

 > B[k]:=value(subs(f(x)=q,b[k]));

 (28)

 > y(x,n)[f=q]:=q+Sum((2*q*sin(Pi*k)/Pi/k)*cos(k*x),k=1..n);

 (29)

 > y(x,n)[f=q]:=                   simplify(subs({sin(Pi*k)=0,cos(Pi*k)=(-1)^k},%));

 (30)

The solution is trivial. For all  k  yields:  y(x, k...n) = q.

 > another_example:=f=1+x;

 (31)

 > A[0]:=value(subs(f(x)=1+x,a[0]));

 (32)

 > A[k]:=value(subs(f(x)=1+x,a[k]));

 (33)

 > limit_value:=Limit(A[k],k=0)=limit(2*sin(Pi*k)/Pi/k,k=0);

 (34)

 > B[k]:=value(subs(f(x)=1+x,b[k]));

 (35)

 > B[k]:=subs({sin(Pi*k)=0,cos(Pi*k)=(-1)^k},%);

 (36)

 > y(x,n)[f=1+x]:=1+Sum(B[k]*sin(k*x),k=1..n);

 (37)

 > y(x,4)[f=1+x]:=value(subs(n=4,%));

 (38)

 > for i in [1,4,100] do         y(x,n=i):=1+subs(n=i,sum(2*sin(Pi*n)*cos(n*x)/Pi/n- (2*(-sin(Pi*n)+cos(Pi*n)*Pi*n)*sin(n*x))/Pi/n^2,                         n=1..i)) od:

 > plot({1,y(x,n=1),y(x,n=4),y(x,n=100)},x=-4*Pi..4*Pi,co=black,      title="FOURIER series # n = [1, 4, 100] for f(x) = 1+x");

FOURIER  Representation of the HEAVISIDE  Function

 > alias(H=Heaviside):

 > F(x)[H_odd]:=H(x)+2*sum((-1)^n*H(x-n*Pi),n=1..N)- H(-x)+2*sum((-1)^n*H(x+n*Pi),n=1..N);

 (39)

 > f(x)[H_odd]:=subs(N=4,%);

 (40)

 > plot(%,x=-4.5*Pi..4.5*Pi,co=black);

 > A[0]:=value(subs(f(x)=f(x)[H_odd],a[0]));

 (41)

 > A[k]:=value(simplify(subs(f(x)=f(x)[H_odd],a[k])));

 (42)

 > B[k]:=simplify(value(subs(f(x)=f(x)[H_odd],b[k])));

 (43)

 > B[k]:=subs(cos(Pi*k)=(-1)^k,%);

 (44)

 > y(x,n)[f=H_odd]:=sum(B[k]*sin(k*x),k=1..n);

 (45)

 > y(x,4)[H_odd]:=value(subs(n=4,%));

 (46)

 > for i in [1,2,3,4,5,6] do                y(x,n=i):=subs(n=i,2*sum(((1-(-1)^n)/Pi/n)*sin(n*x),                     n=1..i)) od;

 (47)

 (47)

 (47)

 (47)

 (47)

 (47)

 > for i in [1,5,99] do         y(x,n=i):=subs(n=i,2*sum(((1-(-1)^n)/Pi/n)*sin(n*x),                     n=1..i)) od:

 > plot({f(x)[H_odd],y(x,n=1),y(x,n=5),y(x,n=99)},                     x=-4.5*Pi..4.5*Pi,co=black);

Interval  ( 0, 2*Pi ):

 > y(x):=alpha[0]/2+          Sum(alpha[k]*cos(k*x)+beta[k]*sin(k*x),k=1..infinity);

 (48)

 > alpha[k]:=(1/Pi)*Int(phi(x)*cos(k*x),x=0..2*Pi);                                # k = 0,1,2,3,...

 (49)

 > alpha[0]:=simplify(subs(k=0,%));

 (50)

 > beta[k]:=(1/Pi)*Int(phi(x)*sin(k*x),x=0..2*Pi);                                 # k = 1,2,3,...

 (51)

 > alias(H=Heaviside,th=thickness,co=color):

 > phi(x,N):=H(x)+2*Sum((-1)^n*H(x-n*Pi),n=1..N);

 (52)

 > phi(x,4):=subs(N=4,%);

 (53)

 > plot(%,x=0..4.5*Pi,co=black);

 > Alpha[0]:=value(subs({phi(x)=phi(x,4),k=0},                           alpha[k]));

 (54)

 > Alpha[k]:=simplify(value(subs(phi(x)=phi(x,4),                       alpha[k])));

 (55)

 > A[k]:=subs({sin(Pi*k)=0,cos(Pi*k)=(-1)^k},%);

 (56)

 > BETA[k]:=simplify(value(subs(phi(x)=phi(x,4),                         beta[k])));

 (57)

 > BETA[k]:=subs(cos(Pi*k)=(-1)^k,%);

 (58)

 > y(x,n):=Sum(BETA[k]*sin(k*x),k=1..n);

 (59)

 > y(x,4):=value(subs(n=4,%));

 (60)

 > for i in [1,3,99] do                                   y(x,n=i):=subs(n=i,y(x,n)) od:

 > plot({y(x,n=1),y(x,n=3),y(x,n=99)},                      x=-4*Pi..8*Pi,co=black);

Continuous Functions with Cusps

 > h(x):=piecewise(x>=0 and x<=1,x,x>=1 and x<=2*Pi,1);

 (61)

 > plot(h(x),x=0..2*Pi,co=black);

 > Alpha[k]:=simplify(value(subs(phi(x)=h(x),alpha[k])));

 (62)

 > Alpha[k]:=subs(sin(k*Pi)=0,%);

 (63)

 > Alpha[0]:=simplify(value(subs(phi(x)=h(x),alpha[0])));

 (64)

 > BETA[k]:=simplify(value(subs(phi(x)=h(x),beta[k])));

 (65)

 > BETA[k]:=subs((cos(k*Pi))^2=1,%);

 (66)

 > y(x,n):=Alpha[0]/2+sum(Alpha[k]*cos(k*x)+               BETA[k]*sin(k*x),k=1..n);

 (67)

 > y(x,1):=evalf(subs(n=1,%),4);

 (68)

 > y(x,3):=evalf(subs(n=3,%%),4);

 (69)

 > y(x,99):=evalf(subs(n=99,%%%),4):

 > for i in [1,3,99] do                                   y(x,n=i):=subs(n=i,y(x,n)) od:

 > plot({y(x,n=1),y(x,n=3),y(x,n=99)},                       x=0..2*Pi,color=black);

L-two Norm

 > L_two[n]:=sqrt((1/2/Pi)*Int((H(x)-Y(x,n))^2,                         x=0..2*Pi));

 (70)

 > for i in [1,3,99] do   L_two[n=i]:=evalf(sqrt((1/2/Pi)*value(int((h(x)-y(x,i))^2,        x=0..2*Pi))),4) od;

 (71)

 (71)

 (71)

For  n = 99  the FOURIER series  y(x, n = 99)  represents a good approximation

to the above given function  h(x).

 > g(x):=piecewise(x<-1,-1,x>-1 and x<1,x,x>1,1);

 (72)

 > plot(g(x),x=-Pi..Pi,co=black);

 > A[k]:=simplify(value(subs(f(x)=g(x),a[k])));

 (73)

 > A[0]:=value(subs(f(x)=g(x),a[0]));

 (74)

 > B[k]:=simplify(value(subs(f(x)=g(x),b[k])));

 (75)

 > B[k]:=subs(cos(Pi*k)=(-1)^k,%);

 (76)

 > y(x,n):=sum(B[k]*sin(k*x),k=1..n);

 (77)

 > y(x,1):=evalf(value(subs(n=1,%)),4);

 (78)

 > y(x,3):=evalf(value(subs(n=3,%%)),4);

 (79)

 > for i in[1,3,99] do y(x,n=i):=subs(n=i,y(x,n)) od:

 > plot({y(x,n=1),y(x,n=3),y(x,n=99)},                      x=-2*Pi..2*Pi,co=black);

 > L_two[n]:=sqrt((1/Pi)*Int((G(x)-Y(x,n))^2,x=0..Pi));

 (80)

 > for i in [1,3,99] do           L_two[n=i]:=evalf(sqrt((1/Pi)*int((g(x)-y(x,i))^2,                   x=0..Pi)),4) od;

 (81)

 (81)

 (81)

 >

For  n = 99  the FOURIER series  y(x, n = 99)  represents a good approximation

to  the above given function  g(x).

Legal Notice: The copyright for this application is owned by the author. Neither Maplesoft nor the author are responsible for any errors contained within and are not liable for any damages resulting from the use of this material. This application is intended for non-commercial, non-profit use only. Contact the author for permission if you wish to use this application in for-profit activities.