function [ c2, z2 ] = newton_append ( c1, z1, x, y )

%*****************************************************************************80
%
%% newton_append updates a Newton interpolant to add a new data pair (x,y).
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    14 November 2019
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real c1(d1+1): the original Newton coefficients.
%
%    real z1(d1+1): the original Newton centers.
%
%    real x, y: the new pair of data values.
%
%  Output:
%
%    real z2(d2+1): the updated Newton centers.
%
%    real c2(d2+1): the updated Newton coefficients.
%
  d1 = length ( z1 ) - 1;
%
%  Move the original data up one index and insert the new data.
%
  d2 = d1 + 1;
  c2 = zeros(d2+1,1);
  c2(2:d2+1) = c1(1:d1+1);
  c2(1) = y;

  z2 = zeros(d2+1,1);
  z2(2:d2+1) = z1(1:d1+1);
  z2(1) = x;
%
%  Recompute the difference table.
%
  for i = 2 : d2 + 1
    c2(i) = ( c2(i) - c2(i-1) ) / ( z2(i) - z2(1) );
  end

  return
end
