function yval = dif_val ( ntab, xtab, diftab, xval )

%*****************************************************************************80
%
%% dif_val() evaluates a divided difference polynomial at a point.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    05 September 2004
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Carl de Boor,
%    A Practical Guide to Splines,
%    Springer Verlag, 1978.
%
%  Input:
%
%    integer NTAB, the number of divided difference
%    coefficients in DIFTAB, and the number of points XTAB.
%
%    real XTAB(NTAB), the X values upon which the
%    divided difference polynomial is based.
%
%    real DIFTAB(NTAB), the divided difference
%    polynomial coefficients.
%
%    real XVAL, the value where the polynomial
%    is to be evaluated.
%
%  Output:
%
%    real YVAL, the value of the polynomial at XVAL.
%
  yval = diftab(ntab);
  for i = 1 : ntab-1
    yval = diftab(ntab-i) + ( xval - xtab(ntab-i) ) * yval;
  end

  return
end
