%Demo Program for Chapter 4 overview
%
%Set up a data set for piecewise interpolation
%
close all
clear all
clc
xlo=0;
xhi=1;
m=200;
%Use the humps function todefine y
yscalar = inline('exp(-2*x)*sin(10*pi*x)');
yv = vectorize(yscalar);
for n = [4 8 16 24]
    %set up data points
    x = linspace(xlo,xhi,n);
    y = yv(x);
    %set up fine grid for evaluation:
    z = linspace(xlo,xhi,m);
    %fz = interp1(x,y,z,'spline'); %piecewise cubic hermite
    fz = interp1(x,y,z,'pchip'); %piecewise cubic hermite
    yz = yv(z);
    figure
    hold on
    plot(z,yz,'-k',z,fz,'-b',x,y,'g*')
    title (['F(x) = exp(-2x)*sin(10pix) with',num2str(n),' data'])
    xlabel('x')
    ylabel ('F(x) or P(x)')
    legend ('function','pchip','data')
    pause
    hold off
end
