# Sept. 12, 2002 # # Fourier Cosine expansion of a triangular function on the interval # [0,1] # > N:=100;L:=1;f:=piecewise(x<0,0,x<1/2,2*x,x<1,-2*x+2,0); > for i from 1 to N do a[i]:=(2/L)*evalf(Int(f*cos(i*Pi*x/L),x=0..L)); > od: > a[0]:=(1/L)*evalf(Int(f,x=0..L)); > for i from 1 to 10 do a[i] od: > i:='i'; > for n from 0 to N do v[n]:=sum(a[i]*cos(i*Pi*x/L),i=0..n) od: > plot([f,v[1],v[5],v[10]],x=0..L,color=[red,blue,green,black]); > plot([f,v[10],v[30],v[50]],x=0..L,color=[red,blue,green,black]); > plot([f,v[25],v[50],v[75],v[100]],x=0..L,color=[red,blue,green,orange, > black]); > plot([f,v[100]],x=0..L,color=[red,black]); # # Remember these plots are not plots of approximations to the solution # of the heat equation, but are plots of approxmations to the initial # data, u(x,0).