%
%  w02fourier_sum.m -- djm -- 15 jan 2008 
%

%  interval (-L < x < +L)
L = pi;

%  parameters
Nterms = 11;  Npts = max(4*Nterms,64);

%  plotting points
dx = 2*L/Npts;  x = -L:dx:L;

%  summation loop
%  j = 0 term
sum = (1/2)*ones(size(x));
%  j = 1,3,5 ...
for j = 1:2:Nterms
    sum = sum + (2/pi/j)*sin(j*x);
end
    
figure(1);  clf
plot([-L -L 0 0 L L],[0.5 0 0 1 1 0.5],'r');  hold on
plot(x,sum,'b')
%plot(x,sum,'k.');
title(['\bf fourier series (example, p37):  up to j=' num2str(Nterms) ' terms'],'fontsize',14)
xlabel('\bf x-axis','fontsize',12)
ylabel('\bf partial sum, S_j(x)','fontsize',12)