function cd = newton_coef_1d ( nd, xd, yd )

%*****************************************************************************80
%
%% NEWTON_COEF_1D computes coefficients of a Newton 1D interpolant.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    04 July 2015
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Carl deBoor,
%    A Practical Guide to Splines,
%    Springer, 2001,
%    ISBN: 0387953663,
%    LC: QA1.A647.v27.
%
%  Parameters:
%
%    Input, integer ND, the number of data values.
%
%    Input, real XD(ND), the X values at which data was taken.
%
%    Input, real YD(ND), the corresponding Y values.
%
%    Output, real CD(ND), the divided difference.
%
  cd(1:nd) = yd(1:nd);

  for i = 2 : nd
    for j = nd : -1 : i
      cd(j) = ( cd(j) - cd(j-1) ) / ( xd(j) - xd(j+1-i) );
    end
  end

  return
end
