function [appcos,appsin,M1,M2] = Fig2x9(t,N)
% To illustrate the approximation of t
% on [-pi,pi] with cosine series
t = [-512:512]/512*pi;
% Initialize with a0/2.... note that a0 = pi;
appcos = pi/2*ones(size(t));
appsin = zeros(size(t));
% Add consecutive terms
for k = 1:N
appcos = appcos + 2/(k^2*pi)*(cos(k*pi)-1)*cos(k*t);
appsin = appsin + 2*(-1)^(k+1)/k*sin(k*t);
plot(t(512:1025),t(512:1025),t(512:1025),appcos(512:1025),t(512:1025),appsin(512:1025));
title('Cosine series in Red, Sine Series in Yellow');
ylim( [-.1 3.7] );
H = gcf;
M1(k) = getframe(H);
plot(t,t,t,appcos,t,appsin);
title('Cosine series in Red, Sine Series in Yellow');
H = gcf;
M2(k) = getframe(H);
end
% M1 is a movie of the results on [0,pi]
% M2 is a movie of the results on [-pi,pi]