% MATH 3150 Fall 2008
% Problem 2.2.13
thickLines (3) ; % remove if you don't have it in your system
figure (1) ;
clf ;
x = linspace(-pi ,3*pi ,1000) ;
% plot true function for reference
hold on ;
% trick to make 2*pi periodic function from fn def on [0,2*pi ]
plot(x ,(mod(x+pi ,2* pi)-pi) ) ;
axis([-pi,3*pi,-pi*1.2, pi*1.2]) ;
% loop over number of terms
Ns = [1 ,2 ,5 ,10 ,15];
cols={'g','m','c','r','k'};
for iN = 1: length(Ns) ,
N=Ns(iN) ;
% compute partial Fourier series
s=zeros( size (x) ) ;
for n=1:N,
an = -2*(-1)^n/n;
s=s+an*sin(n*x) ;
end;
% comparative plot
plot(x,s,cols{iN}) ;
end;%N
hold off ;
xlabel('x') ;
filename='p2_2_13.eps';
print('-depsc2',filename);
system (['epstopdf ',filename]);

