function newton_append_test ( )

%*****************************************************************************80
%
%% newton_append_test tests newton_append
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    16 November 2019
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'newton_append_test\n' );
  fprintf ( 1, '  newton_append updates a Newton polynomial;\n' );
  fprintf ( 1, '  to include a new data item;\n' );
%
%  Set XTAB, YTAB to X, exp(x).
%
  n = 4;
  x = 1:n;
  y = exp ( x );
  vec2_print ( n, x, y, '  The data' );
  [ c, z ] = data_to_newton ( x, y );
  newton_print ( c, z, '  The interpolating Newton polynomial:' );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Interpolation test:\n' );
  fprintf ( 1, '\n' );
  for i = 1 : n
    p = newton_value ( c, z, x(i) );
    fprintf ( 1, '  %8.4f  %8.4f  %8.4f\n', x(i), y(i), p );
  end
%
%  Append a new data item to the table.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Append the data (5,exp(5)) to the table.\n' );
  fprintf ( 1, '\n' );

  n2 = n + 1;
  xval = n2;
  yval = exp ( xval );

  [ c2, z2 ] = newton_append ( c, z, xval, yval );
 
  newton_print ( c2, z2, '  The updated Newton polynomial:' );

  x2 = [ xval, x ];
  y2 = [ yval, y ];
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Interpolation test:\n' );
  fprintf ( 1, '\n' );
  for i = 1 : n2
    p2 = newton_value ( c2, z2, x2(i) );
    fprintf ( 1, '  %8.4f  %8.4f  %8.4f\n', x2(i), y2(i), p2 );
  end

  return
end
