%% Hermite interpolation of the exponential on -1 <= z <= 1
%
% We use $\eta_k = \cos( \pi k /n )$ with $n=4$ and increasing 
% confluencies in an experimental fashion.
%
n = 15;
tau = [cos( pi*(n:-1:0)/n ) ];
z = linspace(-1,1,2012);
yref = exp(z);
vals = exp( tau );
niters = 4;
yint = zeros( niters, length(z) );
ypint= zeros( niters, length(z) );
errs = zeros( size(yint) );
errps= zeros( size(errs) );
for s=1:niters,
    fac = ones(s,1);
    for j=3:s,
        fac(j) = fac(j-1)/(j-1);
    end
    rho = fac*vals; % Local Taylor coeffs have factorials!
    [w,D] = genbarywts( tau, s );
    [y,yp] = hermiteval( rho, z, tau, s, w, D );
    yint(s,:) = y;
    ypint(s,:) = yp;
    errs(s,:) = yint(s,:)./yref - 1;
    errps(s,:) = ypint(s,:)./yref - 1;
end
figure(1), semilogy( z, abs(errs), 'k' ), set(gca,'fontsize',16)
xlabel('z'), ylabel('y/exp(z) - 1')
figure(2), semilogy( z, abs(errps), 'k' ), set(gca,'fontsize',16)
xlabel('z'), ylabel('y''/exp(z)-1')