function ShowCosBasis()
% Suppose f(z) is defined on [0,1] and that we want to interpolate its value
% at x = [1 3 5 7 9 11 13 15]/16 with the following function:
% p(z) = a(1)*cos(0*pi*z) + ...
% a(2)*cos(1*pi*z) + ...
% a(3)*cos(2*pi*z) + ...
% a(4)*cos(3*pi*z) + ...
% a(5)*cos(4*pi*z) + ...
% a(6)*cos(5*pi*z) + ...
% a(7)*cos(6*pi*z) + ...
% a(8)*cos(7*pi*z)
% If y(i) = f(x(i)), then the unknowns a(1),...,a(8) solve a linear system
% Ma = y where M(i,j) = cos((1:2:15)'*(0:7)*pi/16). (Notethat M = C8').

% This script displays the basis functions cos(j*pi*z) and the evaluations
% that make up each column of M:

close all
for i=1:8
% Plot cos(j*ppi*z) across [0,1]...
xVals = linspace(0,1);
yVals = cos(pi*(i-1)*xVals);
plot(xVals,yVals,'m','linewidth',3)
% Display the points where we sample this function...
hold on
x0 = (1:2:15)/16;
y0 = cos(pi*(i-1)*x0);
plot(x0,y0,'.r','markersize',30)
% Display the x-axis....
plot([0,1],[0 0],'-k')
hold off
axis([0 1 -1.1 1.1])
title(sprintf('cos(%1d*pi*x)',i-1),'fontsize',18)
xlabel(sprintf('Function values reported in M(:,%1d)',i),'fontsize',18)
shg
pause
end