function spline_test127 ( )

%*****************************************************************************80
%
%% spline_test127() tests least_set() and least_val2().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    29 January 2005
%
%  Author:
%
%    John Burkardt
%
  point_num = 21;
  nterms = 4;

  w(1:point_num) = 1.0;

  for i = 1 : point_num
    x(i) = -1.0 + ( i - 1 ) / 10.0;
    f(i) = x(i)^2 - x(i) - 6.0;
    fp(i) = 2.0 * x(i) - 1.0;
  end
 
  [ b, c, d ] = least_set ( point_num, x, f, w, nterms );
 
  fprintf ( 1, '\n' );
  fprintf ( 1, 'TEST127\n' );
  fprintf ( 1, '  LEAST_SET sets a least squares polynomial,\n' );
  fprintf ( 1, '  LEAST_VAL2 evaluates it.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  X, F(X), P(X), FP(X), PP(X)\n' );
  fprintf ( 1, '\n' );
 
  for nterms2 = 1 : nterms
    fprintf ( 1, '\n' );
    fprintf ( 1, '  Using polynomial order = %d\n', nterms2 );
    fprintf ( 1, '\n' );
    for i = 1 : point_num
      [ px, pxp ] = least_val2 ( nterms2, b, c, d, x(i) );
      fprintf ( 1, '  %10f  %10f  %10f  %10f  %10f\n', ...
        x(i), f(i), px, fp(i), pxp );
    end
  end

  return
end
