%--------------------------------------------
function partial_sum(L,N)
%--------------------------------------------
% To execute type the following in the command window:
% >> partial_sum(2,10)
% ( >> is the matlab prompt; be sure to go to file/set path 
% and set the matlab path to the directory where you save this script as
% partial_sum.m; above command will set L=2, N=10; experiment with
% different values. )
%--------------------------------------------
% computes the partial sums of a Fourier series
% for different functions, change the definition of Fourier coefficients
% accordingly. The present routine plots the partial sums for the 
% sine series of the function f(x) = x, 0<x<L , over the interval -2L<x<2L
x = linspace(-2*L,2*L,10*N+1);
y0 = zeros(10*N+1,1);
pi_L = pi/L;
y = 0;
for n = 1:N
   y = y + (-1)^(n+1)*sin(n*pi_L*x)/n;
end
y = 2/pi_L * y;
plot(x,y,'r-',x,y0,'k-')
%--------------------------------------------
