%:::::::::::::::::::::::::::::::::::::::::::::::::::::
% script: Partial_sums
% compute and plot partial sums of step function
% and sine series expansion of cosine:
   clear all;close all
  % N = [4 8 16 32];
   L = 1;
   x = linspace(0,1,201);
    k=0;
    hold on
    for N = [4 8 16 32]
        k = k+1; sum = 0;
   for i = 1:N
% step function
      ipi = i*pi;
%     sum = sum + 2/ipi*(1-cos(ipi/2))*sin(ipi*x/L);
% cosine function
      sum = sum + (8/pi)*(i/(4*i*i-1))*sin(2*ipi*x/L);
   end
   subplot(2,2,k); plot(x,sum);title(sprintf('N = %3.0f',N))
end
hold off
%:::::::::::::::::::::::::::::::::::::::::::::::::::::

