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

