> | restart:MAX:=200:A:=0:B:=2:p:=1/2*(B-A):pleft:=-.2:pright:=1.01:pup:=1.5:pdown:=0.5:P:=2*p:with(plots): |
Warning, the name changecoords has been redefined
> | f(t):=piecewise(t<A,0, t>A and t<1/2*(B-A),1,t>1/2*(B-A), -1,t>B ,0);plot(f(t),t=-0.5..2); |
> | 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;plot(fperiodic,-10..10); |
> | 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); |
> |
> | ORIGINAL:=plot(f(t),t=pleft..pright,color=yellow,thickness=5,discont=true):FPERIODIC:=plot(fperiodic,pleft..pright,color=red):F:=plot(fs[N](t),t=pleft..pright,color=blue): |
> | for N from 1 to MAX do 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):F[N]:=plot([fs[N](t),f(t)],t=pleft..pright,y=pup..pdown,color=[blue,red],numpoints=500):od: |
> | S:=seq(F[N],N=1..MAX): |
> | display(S,insequence=true); |
> |
> |
> |
> |
> |
> |
> |
> |
> |
> |
> |
> |
> |
> |
> |
> |
> |