% PLOTABSSIN  Plot h(x)=|sin(x)|, and the ninth partial sum of its Fourier
%             series, on the interval [-4,4].

% build partial sum:
x = linspace(-4,4,2001);                            % Matlab needs x coordinates to plot
C = 1/(2*pi);                                       % normalization constant
y = (4) * C*ones(size(x));                          % constant term
for k=1:4                                           % n=2k; thus n=0,1,2,...,8
    y = y + (8/(1-4*k*k)) * C*cos(2*k*x);
end

plot(x,abs(sin(x)),'--',x,y)
legend('h(x)','ninth partial sum')
set(gca,'XTick',[-pi 0 pi])                         % shows interval [-pi,pi] clearly
set(gca,'XTickLabel',['-pi'; ' 0 '; 'pi '])         % mere beautification
