function evaluation_compare ( x )

%*****************************************************************************80
%
%% evaluation_compare compares methods of evaluating a polynomial.
%
%  Discussion:
%
%    The power sum form of a polynomial is:
%
%      p(x) = c(0) + c(1) * x + ... + c(n-1) * x^(n-1) + c(n) * x^(n)
%
%    Because MATLAB doesn't allow 0 indexing, we use an adjusted formula:
%
%      p(x) = c(1) + c(2) * x + ... + c(n) * x^(n-1) + c(n+1) * x^(n)
%
%  Input:
%
%    real X, the argument where the polynomial should be evaluated.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'evaluation_compare:\n' );
  fprintf ( 1, '  Compare methods of polynomial evaluation.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  De Boor, Exercise 2.1-1, page 37: Evaluate the cubic\n' );
  fprintf ( 1, '  polynomial p(x)=(x-99 pi)(x-100 pi)(x-101 pi) at\n' );
  fprintf ( 1, '  x=314.15.  Then use nested multiplication to obtain p(x)\n' );
  fprintf ( 1, '  in power form, and evaluate the power form at x=314.15\n' );
  fprintf ( 1, '  and compare!\n' );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Do calculations in double precision (the default).\n' );
  fprintf ( 1, '\n' );

  p_factor = [ 99.0*pi; 100.0*pi; 101.0*pi ];
  p_power = [ -999900*pi^3; 29999*pi^2; -300.0*pi; 1.0 ];

  value = poly_value_termwise ( p_power, x );
  fprintf ( 1, '  Power form, term-by-term evaluation = %20.16f\n', value );

  value = poly_value_nested ( p_power, x );
  fprintf ( 1, '  Power form, nested evaluation       = %20.16f\n', value );

  value = factor_value ( p_factor, x );
  fprintf ( 1, '  Factor form, product evaluation     = %20.16f\n', value );

  value = polyval ( p_power(end:-1:1), x );
  fprintf ( 1, '  Power form, polyval evaluation      = %20.16f\n', value );
%
%  Repeat in single precision.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Repeat, in single precision.\n' );
  fprintf ( 1, '\n' );

  value = poly_value_termwise_single ( p_power, x );
  fprintf ( 1, '  Power form, term-by-term evaluation = %20.16f\n', value );

  value = poly_value_nested_single ( p_power, x );
  fprintf ( 1, '  Power form, nested evaluation       = %20.16f\n', value );

  value = factor_value_single ( p_factor, x );
  fprintf ( 1, '  Factor form, product evaluation     = %20.16f\n', value );

  value = polyval ( single ( p_power(end:-1:1) ), single ( x ) );
  fprintf ( 1, '  Power form, polyval evaluation      = %20.16f\n', value );

  return
end

