% MATH 3150 Fall 2008
%
problem 2.2.7
thickLines (3) ; % remove if it is not in your system
figure (1) ;clf ;
x = linspace(-pi , pi ,1000) ;
% plot true function for reference
hold on ;
plot(x , abs( sin (x) ) ) ; % function is 2pi periodic already
axis([-pi , pi ,0 ,1.1]) ;
% 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=2/pi*ones ( size (x) ) ;
for k=1:N,
an = 4/pi/(1-(2*k)^2) ;
s=s+an*cos(2*k*x) ;
end;
% comparative plot
plot(x , s , cols {iN}) ;
end;%N
hold off ;
xlabel( 'x' ) ;
filename='p_2_2_7.eps' ;
print('-depsc2' , filename ) ;
system (['epstopdf ' , filename ]) ;














