Some Fourier Series Expansions
Example 3 (Lecture)
> | restart:N:=5:p:=2:A:=-2:B:=2:pleft:=-5:pright:=5:with(plots): |
> | f(t):=piecewise(t<A,0, t>A and t<B,4-t^2,t>B ,0); |
Warning, the name changecoords has been redefined
> |
> | a[0]:=1/p*int(f(t),t=-2..2); |
> | a[n]:=1/p*int(f(t)*cos(n*Pi*t/p),t=-2..2); b[n]:=1/p*int(f(t)*sin(n*Pi*t/p),t=-2..2); |
> | b[n] := 0; |
> | fs[N](t):=1/2*a[0]+ sum(a[n]*cos(n*Pi*t/p)+b[n]*sin(n*Pi*t/p),n=1..N); |
> |
> | fpe:=proc(x) local y;y:=x; while y < A do y:=y+2*p;od; while y > B do y:=y-2*p;od;evalf(subs(t=y,f(t)));end; |
> |
> | Pf:=plot(fpe,pleft..pright,numpoints=200):Pfs:=plot(fs[N](t),t=pleft..pright,color=blue,numpoints=500): |
> | display(Pf,Pfs); |
> |
> |
> |
Example 4 (Lecture)
> | restart:N:=5:p:=1:A:=0:B:=2:pleft:=-5:pright:=5:with(plots): |
Warning, the name changecoords has been redefined
> | f(t):=piecewise(t<A,0, t>A and t < 1,1+t^2, t>1 and t<B, 3-t,t>B ,0);plot(f(t),t=-5..5); |
> |
> | a[0]:=1/p*int(f(t),t=A..B); |
> | a[n]:=1/p*int(f(t)*cos(n*Pi*t/p),t=A..B); b[n]:=1/p*int(f(t)*sin(n*Pi*t/p),t=A..B); |
> | fs[N](t):=1/2*a[0]+ sum(a[n]*cos(n*Pi*t/p)+b[n]*sin(n*Pi*t/p),n=1..N); |
> | fpe:=proc(x) local y;y:=x; while y < A do y:=y+2*p;od; while y > B do y:=y-2*p;od;evalf(subs(t=y,f(t)));end; |
> |
> | Pf:=plot(fpe,pleft..pright,numpoints=200):Pfs:=plot(fs[N](t),t=pleft..pright,color=blue,numpoints=500): |
> | display(Pf,Pfs); |
> |
> |
Problem 8.4:3
> | restart:N:=5:p:=2:A:=0:B:=2*p:pleft:=-5:pright:=5:with(plots): |
Warning, the name changecoords has been redefined
> | f(t):=piecewise(t<A,0, t>A and t < p,1-t,t>p and t<2*p, 0 ,t>B ,0);plot(f(t),t=-5..5); |
> |
> | a[0]:=1/p*int(f(t),t=A..B); |
> | a[n]:=1/p*int(f(t)*cos(n*Pi*t/p),t=A..B); b[n]:=1/p*int(f(t)*sin(n*Pi*t/p),t=A..B); |
> | fs[N](t):=1/2*a[0]+ sum(a[n]*cos(n*Pi*t/p)+b[n]*sin(n*Pi*t/p),n=1..N): |
> | fpe:=proc(x) local y;y:=x; while y < A do y:=y+2*p;od; while y > B do y:=y-2*p;od;evalf(subs(t=y,f(t)));end; |
> |
> | Pf:=plot(fpe,pleft..pright,numpoints=200):Pfs:=plot(fs[N](t),t=pleft..pright,color=blue,numpoints=500): |
> | display(Pf,Pfs); |
> |
> |
> |
Problem 8.2:6
> | restart:N:=5:p:=1/2*(B-A):A:=0:B:=2*evalf(Pi):pleft:=-10:pright:=8:with(plots): |
Warning, the name changecoords has been redefined
> | f(t):=piecewise(t<A,0, t>A and t < 2*Pi/3,0, t>2*Pi/3 and t <4*Pi/3, 1, t > 4*Pi/3 and t < B, 2, t>B, 0);plot(f(t),t=0..8); |
> |
> | a[0]:=1/p*int(f(t),t=A..B); |
> | a[n]:=1/p*int(f(t)*cos(n*Pi*t/p),t=A..B); b[n]:=1/p*int(f(t)*sin(n*Pi*t/p),t=A..B); |
> | fs[N](t):=1/2*a[0]+ sum(a[n]*cos(n*Pi*t/p)+b[n]*sin(n*Pi*t/p),n=1..N); |
> | fpe:=proc(x) local y;y:=x; while y < A do y:=y+2*p;od; while y > B do y:=y-2*p;od;evalf(subs(t=y,f(t)));end; |
> | fpe(2); |
> | Pf:=plot(fpe,pleft..pright,numpoints=200):Pfs:=plot(fs[N](t),t=pleft..pright,color=blue,numpoints=500): |
> | display(Pf,Pfs); |
> |
> |
> |
> |
> |