%
%  w04one.m
%

%  initialize workspace & set some control variables
clear;
Nt = 128;  Np = 16*Nt;  %  number of plot points

%  set x (row) vector
dx = pi/Np;  x = -pi+dx:dx:pi;

%  fourier series 
ye = 0;
for j = 1:2:Nt
    ye = ye + (4/pi/j)*sin(j*x);
end

%  choose figure & clear 
figure(1);
clf;  hold on

%plot(x,ye,'k.');  
plot(x,ye,'b');

title('\bf non-absolutely convergent sine series')
xlabel('\bf x-axis')
ylabel('\bf F(x)')
axis([-pi pi -1.25 1.25])

%  choose figure & clear 
figure(2);
%clf;  hold on

plot(x,ye,'k');

title('\bf close-up')
xlabel('\bf x-axis')
ylabel('\bf F(x)')
axis([0 pi/8 0.75 1.25])

%  re-ordered series
yr = 0;
for j = 1:4:2*Nt
    yr = yr + (4/pi/j)*sin(j*x);
end
for j = 3:4:Nt
    yr = yr + (4/pi/j)*sin(j*x);
end

%  choose figure & clear 
figure(3);
%clf;

subplot(2,1,1);
%plot(x,yr,'b');  axis([-pi pi -1.25 1.25])
title('\bf re-ordered sine series')

subplot(2,1,2);  hold on
plot(x,yr,'k');  axis([7*pi/16 9*pi/16 0.75 1.25])

xlabel('\bf x-axis')
ylabel('\bf F_r(x)')
