function fsm = fourier_movie(f,x,a,b,c,d,n) % This animates the first n partial sums of the Fourier series of the % expression f on the interval [a,b]. The function is assumed to be % periodic with period L = b-a. The vertical axis goes from c to d. L = (b-a); X = a:0.001:b; g = inline(vectorize(f)); partsum = 1/L * double(int(f,x,a,b)); for k =1:n partsum = partsum ... + 2/L*double(int(f*sin(2*k*pi*x/L),x,a,b))*sin(2*k*pi*x/L) ... + 2/L*double(int(f*cos(2*k*pi*x/L),x,a,b))*cos(2*k*pi*x/L); ps2 = inline(vectorize(partsum)); plot(X,g(X),'r'), hold on plot(X,ps2(X)), hold off axis([a b c d]) fsm(k) = getframe; end