%
% 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 this problem, the coefficients and basis functions are (see notes):
% an = (4/pi)/m gn(x) = sin(m*pi*x/L)
% with m = (2n-1) and n = 1, 2, ...
%
% Note: This implementation is not very efficient or elegant, but it
% is fairly straightforward. A related example, EIGENF2.M, gives a more
% efficient set of coding for evaluating infinite series.
%
% File prepared by J. R. White, UMass-Lowell (Aug. 2003))
%
%
% getting started
clear all, close all, nfig = 0;
%
% set x domain and some constants
L = 3; x = linspace(0,L,201); c = 4/pi;
%
% calc 1st partial sum
s1 = c*sin(pi*x/L);
%
% calc 5th partial sum
s5 = s1;
for n = 2:5
m = 2*n-1; s5 = s5 + (c/m)*sin(m*pi*x/L);
end
%
% calc 20th partial sum
s20 = s5;
for n = 6:20
m = 2*n-1; s20 = s20 + (c/m)*sin(m*pi*x/L);
end
%
% calc 50th partial sum
s50 = s20;
for n = 21:50
m = 2*n-1; s50 = s50 + (c/m)*sin(m*pi*x/L);
end
%
% plot curves
nfig = nfig+1; figure(nfig)
subplot(2,1,1),plot(x,s1,'g-',x,s5,'r--','LineWidth',2),grid
title('Eigen1: Truncated Fourier Series Approx to f(x) = 1')
ylabel('Approx f(x)')
legend('1st Partial Sum','5th Partial Sum')
%
subplot(2,1,2),plot(x,s20,'g-',x,s50,'r--','LineWidth',2),grid
xlabel('x-values'),ylabel('Approx f(x)')
legend('20th Partial Sum','50th Partial Sum')
%
% end of demo