%
% Figures 3.2
%
clear all
t=-1.5:0.01:1.5;
wo=4, E=1; 
N=1;
xN=0;
for n=1:N
    an=(E/(n*pi))*(sin(n*pi/2)-sin(n*3*pi/2))
    xN=xN+an.*cos(n*wo*t);
end
% .* indicates the pointwise multiplication
plot(t,xN,':')
hold
N=3;
xN=0;
for n=1:N
    an=(E/(n*pi))*(sin(n*pi/2)-sin(n*3*pi/2))
    xN=xN+an.*cos(n*wo*t);
end
plot(t,xN,'--')
N=5;
xN=0;
for n=1:N
    an=(E/(n*pi))*(sin(n*pi/2)-sin(n*3*pi/2))
    xN=xN+an.*cos(n*wo*t);
end
plot(t,xN)
print -deps fig3_2.eps
