function pp = LCpp(x,f) 
% usage: pp = LCpp(x,f) 
% description:  this function returns a PP structure representing
% the Lagrange cubic p.p. with knot row vector consisting of 
% the first entry and every subsequent third entry of x, counting
% from the second entry of x.  It is understood that the ordered
% node row vector x includes the intermediate nodes needed for
% Lagrange interpolation and that these are not counted as knots.
% Therefore, x and f must have length 3*k-2 where
%     k = number of knots.

% local variables: 
% n,m: size of node and value arrays
% j,knotindex:  index variables

n = length(x);
m= size(f);
m = m(1)+m(2)-1;
if (m ~= n) % error check for size and order
  disp('Size mismatch of abscissa and ordinate');
  return;
end;
if (rem(n,3)~=1)
  disp('Abscissa size is not 3*k+1');
  return;
end;
for j = 2:n
  if (x(j) <= x(j-1))
    disp('Nodes vector is not strictly increasing')
    return;
  end;
end;
% size ok, construct PP structure
pp = PP(4, round((n-1)/3)+1, x(1:3:n));
% determine the poly coefs in each knot subinterval
knotindex = 1;
for j = 1:3:(n-1)
  % set up and solve the system on this subinterval
  pp.coefs(knotindex,:) = (vander(x(j:j+3) - x(j))\f(j:j+3)')'; 
  knotindex = knotindex+1;
end;
