m07.mws

Fourier Half and Quarter Range Expansions

>    restart:N:=5:A:=0:B:=2:pleft:=-8:pright:=8:with(plots):

Warning, the name changecoords has been redefined

Extensions of functions

>    f(t):=piecewise(t<A,0, t>A and t<B,4-t^2,t>B ,0);plot(f(t),t=-5..5);

f(t) := PIECEWISE([0, t < 0],[4-t^2, -t < 0 and t < 2],[0, 2 < t])

[Maple Plot]

  Even Extension of f:

>    ef:=proc(x) if x>=2*A-B and x < A then evalf(subs(t=2*A-x,f(t))) elif x>=A and x<=B then evalf(subs(t=x,f(t))) else 0 fi; end;

ef := proc (x) if 2*A-B <= x and x < A then evalf(subs(t = 2*A-x,f(t))) elif A <= x and x <= B then evalf(subs(t = x,f(t))) else 0 end if end proc

>    ef(1);plot(ef,-5..5);

3.

[Maple Plot]

Odd Extension of f:

>    of:=proc(x) if x>=2*A-B and x < A then evalf(subs(t=2*A-x,-f(t))) elif x>=A and x<=B then evalf(subs(t=x,f(t))) else 0 fi; end;

of := proc (x) if 2*A-B <= x and x < A then evalf(subs(t = 2*A-x,-f(t))) elif A <= x and x <= B then evalf(subs(t = x,f(t))) else 0 end if end proc

>    plot(of,-10..10);

[Maple Plot]

>   

Periodic Extensions

>    Phalf:=B-A:Pquarter:=2*(B-A):P:=(B-A):

>    fperiodic:=proc(x) local y;y:=x; while y < A do y:=y+P;od; while y > B do y:=y-P;od;evalf(subs(t=y,f(t)));end;

fperiodic := proc (x) local y; y := x;  while y < A do y := y+P end do;  while B < y do y := y-P end do; evalf(subs(t = y,f(t))) end proc

>    fpeven:=proc(x) local y;y:=x; while y < 2*A-B do y:=y+2*Phalf;od; while y > B do y:=y-2*Phalf; od; ef(y);end;

fpeven := proc (x) local y; y := x;  while y < 2*A-B do y := y+2*Phalf end do;  while B < y do y := y-2*Phalf end do; ef(y) end proc

>    fpodd:=proc(x) local y;y:=x; while y < 2*A-B do y:=y+2*Phalf;od; while y > B do y:=y-2*Phalf; od; of(y);end;

fpodd := proc (x) local y; y := x;  while y < 2*A-B do y := y+2*Phalf end do;  while B < y do y := y-2*Phalf end do; of(y) end proc

>    plot(fpeven,-20..10);

[Maple Plot]

>    plot(fpodd,-20..10);

[Maple Plot]

>    plot(fperiodic,-20..10);

[Maple Plot]

Half Range Expansions

>    p:=B-A:pp:=1/2*(B-A):

>    a[0]:=2/p*int(f(t),t=A..B);aa[0]:=1/pp*int(f(t),t=A..B);

a[0] := 16/3

aa[0] := 16/3

>    aa[n]:=1/pp*int(f(t)*cos(n*Pi*t/pp),t=A..B); bb[n]:=1/pp*int(f(t)*sin(n*Pi*t/pp),t=A..B);

aa[n] := -4*(2*n*Pi*cos(n*Pi)^2-n*Pi-sin(n*Pi)*cos(n*Pi))/n^3/Pi^3

bb[n] := 4*(1-2*n*Pi*sin(n*Pi)*cos(n*Pi)-cos(n*Pi)^2+n^2*Pi^2)/n^3/Pi^3

>    a[n]:=2/p*int(f(t)*cos(n*Pi*t/p),t=A..B); b[n]:=2/p*int(f(t)*sin(n*Pi*t/p),t=A..B);

a[n] := -16*(n*Pi*cos(n*Pi)-sin(n*Pi))/n^3/Pi^3

b[n] := -8*(-2+2*n*Pi*sin(n*Pi)+2*cos(n*Pi)-n^2*Pi^2)/n^3/Pi^3

>    fs[N](t):=1/2*aa[0]+sum(aa[n]*cos(n*Pi*t/pp)+bb[n]*sin(n*Pi*t/pp),n=1..N);

fs[5](t) := 8/3-4/Pi^2*cos(Pi*t)+4/Pi*sin(Pi*t)-1/Pi^2*cos(2*Pi*t)+2/Pi*sin(2*Pi*t)-4/9*1/Pi^2*cos(3*Pi*t)+4/3*1/Pi*sin(3*Pi*t)-1/4*1/Pi^2*cos(4*Pi*t)+1/Pi*sin(4*Pi*t)-4/25*1/Pi^2*cos(5*Pi*t)+4/5*1/Pi*...

>    fsine[N](t):=sum(b[n]*sin(n*Pi*t/p),n=1..N);

fsine[5](t) := -8*(-4-Pi^2)/Pi^3*sin(1/2*Pi*t)+4/Pi*sin(Pi*t)-8/27*(-4-9*Pi^2)/Pi^3*sin(3/2*Pi*t)+2/Pi*sin(2*Pi*t)-8/125*(-4-25*Pi^2)/Pi^3*sin(5/2*Pi*t)

>    fcosine[N](t):=1/2*a[0]+ sum(a[n]*cos(n*Pi*t/p),n=1..N);

fcosine[5](t) := 8/3+16/Pi^2*cos(1/2*Pi*t)-4/Pi^2*cos(Pi*t)+16/9*1/Pi^2*cos(3/2*Pi*t)-1/Pi^2*cos(2*Pi*t)+16/25*1/Pi^2*cos(5/2*Pi*t)

>    FSINE:=plot(fsine[N](t),t=pleft..pright,color=blue):FCOSINE:=plot(fcosine[N](t),t=pleft..pright,color=blue):F:=plot(fs[N](t),t=pleft..pright,color=blue):

>    FEVEN:=plot(fpeven,pleft..pright,color=red):FPERIODIC:=plot(fperiodic,pleft..pright,color=red):

>    ORIGINAL:=plot(f(t),t=pleft..pright,color=yellow,thickness=5,discont=true):

>    FODD:=plot(fpodd,pleft..pright,color=red):

>    display(FSINE,FODD,ORIGINAL);

[Maple Plot]

>   

>    display(FCOSINE,FEVEN,ORIGINAL);

[Maple Plot]

>    display(F,FPERIODIC,ORIGINAL);

[Maple Plot]

>