% % EIGENF1.M Demo of Fourier Series Representation for f(x) = 1 % % The goal here is to evaluate the infinite series expansion for % f(x) = 1 in terms of sinusoids (i.e. a Fourier series expansion) % % For normalized eigenfunctions, the coefficients and basis functions % are: % an = 2*sqrt(2/pi)/m gn(x) = sqrt(2/pi)*sin(mx) % with m = (2n-1) and n = 1, 2, ... % % For unnormalized eigenfunctions, the coefficients and basis functions % are : % an = (4/pi)/m gn(x) = sin(mx) % with m = (2n-1) and n = 1, 2, ... % % File prepared by J. R. White, UMass-Lowell (original Nov. 1996) % --> minor modifications (Aug. 1998) % % % getting started clear all, close all % % set x domain x = linspace(0,pi,201); c = 4/pi; % % calc 1st partial sum s1 = c*sin(x); % % calc 5th partial sum s5 = s1; for n = 2:5 m = 2*n-1; s5 = s5 + (c/m)*sin(m*x); end % % calc 20th partial sum s20 = s5; for n = 6:20 m = 2*n-1; s20 = s20 + (c/m)*sin(m*x); end % % calc 50th partial sum s50 = s20; for n = 21:50 m = 2*n-1; s50 = s50 + (c/m)*sin(m*x); end % % plot curves v = [0 pi 0 1.4]; subplot(2,1,1),plot(x,s1,'g-',x,s5,'r--'),grid,axis(v) title('Truncated Fourier Series Approx to f(x) = 1') ylabel('Approx f(x) = 1') legend('1st PSum','5th PSum') % subplot(2,1,2),plot(x,s20,'g-',x,s50,'r--'),grid,axis(v) xlabel('x-values'),ylabel('Approx f(x) = 1') legend('20th PSum','50th PSum') % % end of demo %