function lagrange_sum_test ( )

%*****************************************************************************80
%
%% lagrange_sum_test() tests lagrange_sum().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    06 October 2024
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'lagrange_sum_test():\n' );
  fprintf ( 1, '  lagrange_sum() evaluates a Lagrange interpolant.\n' );
%
%  Values of f(x) = x^3 - 12 x^2 + 39 x -28 = ( x - 1 ) * ( x - 4 ) * ( x - 7 )
%
  nd = 4;
  xd = [ 0.0, 2.0, 5.0, 10.0 ];
  yd = [ -28.0, +10.0, -8.0, +162.0 ];
 
  w = lagrange_rule ( nd, xd );

  ni = 11;
  xi = linspace ( 0.0, 10.0, ni );

  fprintf ( 1, '\n' );
  fprintf ( 1, '       x      f(x)    Interp\n' );
  fprintf ( 1, '\n' );
  for i = 1 : ni
    yexact = xi(i)^3 - 12 * xi(i)^2 + 39 * xi(i) - 28;
    yi = lagrange_sum ( nd, xd, w, yd, xi(i) );
    fprintf ( 1, '  %10.4f  %14.6g  %14.6g\n', xi(i), yexact, yi );
  end

  return
end

