function interpolatePL

% piecewise linear interpolation of f(x) for a<x<b

a=0; b=1;

% data points
nd=8
xd=linspace(a,b,nd);
for iy=1:nd
	yd(iy)=f(xd(iy));
end

% exact values
n=400;
xp=linspace(a,b,n);
for i=1:n
	y(i)=f(xp(i));
end

% plot curves
% this uses the fact that MATLAB draws straight lines betwen data points
clf
% get(gcf)
set(gcf,'Position', [25 1115 658 230])
co = [0 0 1;
      0 0.5 0;
      1 0 0;
      0 0.75 0.75;
      0.75 0 0.75;
      0.75 0.75 0;
      0.25 0.25 0.25];
set(groot,'defaultAxesColorOrder',co)

hold on
box on
plot(xp,y,'--r','LineWidth',1.8)
plot(xd,yd,'-b','LineWidth',1.6)
plot(xd,yd,'or','MarkerSize',7,'LineWidth',2)
grid on
xlabel('x-axis')
ylabel('y-axis')
legend({' Exact',' PL Interpolation'},'Location','North','FontSize',16,'FontWeight','bold')
set(gca,'FontSize',16,'FontWeight','bold')


function g=f(x)
g=cos(2*pi*x);









