%
%  hw02c.m
%

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

%  set x (row) vector (type "x" at the >>)
dxc = pi/Np;  xc = pi-8*pi/Nt:dxc:pi;
dxs =  1/Np;  xs = 1-8/Nt:dxs:1;

%  fourier series 
fc = (pi^2)/3;  fs = 0;
for j = 1:Nt
    fc = fc + 4*((-1)^j)*cos(j*xc)/(j^2);
    fs = fs + (2/pi^3)*((2-(j*pi)^2)*(-1)^j - 2)*sin(j*pi*xs)/(j^3);
end

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

err = (xc.^2)-fc;  err = err/err(end);
plot(Nt*(xc-pi)/pi,err,'b');

title('\bf self-similarity exercise')
xlabel('\bf z-axis')
ylabel('\bf e_N(z)')

axis([-8 0 -0.4 1.0])

figure(2);  %clf
hold on

err = (xs.^2)-fs;  err = err;
plot(Nt*(xs-1),err,'b');

axis([-8 0 -0.2 1.0])

title('\bf self-similarity exercise')
xlabel('\bf z-axis')
ylabel('\bf e_N(z)')

