function ShowpchipSlope()
% Looks a simple example of piecewise cubic hermite interpolation
% across 4 subintervals. We play with the slope at x(3) and observe
% the shape preserving quality of the overall fit

x = [ -1  0 1 3  4]';
y = [  1 -2 1 2  1]';
z = linspace(-1,4)';
% Compute the optimal slope at x(3) using the pchip idea of taking
% a weighted harmonic average of (y(4)-y(3))/(x(4)-x(3)) and
% (y(3)-y(2))/(x(3)-x(2))...
hk   = x(4)-x(3);  dyk   = y(4)-y(3);
hkm1 = x(3)-x(2);  dykm1 = y(3)-y(2);
w1 = 2*hk + hkm1;
w2 = hk + 2*hkm1;
sopt = (w1+w2)/(w1/dykm1 + w2/dyk);
% Try various values for s(3) and then the optimal choise...
for s3 = [-3:.25:3 sopt]
    s = [ -1 0 s3 0 -1]';
    [a,b,c,d] = pwC(x,y,s);
    cVals = pwCeval(a,b,c,d,x,z);
    plot(z,cVals,[-2 5],[0 0],'b-',x,y,'.k','markersize',25)
    hold on
    plot(1,1,'.r','markersize',25)
    hold off
    axis([-2 5 -3 3])
    title(sprintf('c''(1) = %5.3f',s3),'fontsize',18)
    shg
    pause
end
xlabel('Optimum slope','fontsize',18)