function pp = HCpp(x,f,fp) 
% usage: pp = HCpp(x,f,fp) 
% description: this function returns a PP structure representing
% the Hermite cubic p.p. with node row vector x, corresponding
% function values in the row vector f and derivative values in the
% row vector fp.


% local variables: 
% n,m: size of node and value arrays
% j: index variable
% h: stepsize

n = length(x);
m= size(f);
m = m(1)+m(2)-1;
if (m ~= n) % error check for size and order
  error('Size mismatch of abscissa and function ordinate');
end;
m = length(fp);
if (m ~= n) % error check for size and order
  error('Size mismatch of abscissa and derivative ordinate');
end;
pp = PP(4, n, x);
% determine the poly coefs in each knot subinterval
for j = 1:(n-1)
  % use differences to determine the coefficients
  h = x(j+1) - x(j);
  fab = (f(j+1)-f(j))/h;
  pp.coefs(j,:) = [(fp(j)+fp(j+1)-2*fab)/(h*h),(3*fab-2*fp(j)-fp(j+1))/h,fp(j), f(j)];
end;
