function ortval_test ( )

%*****************************************************************************80
%
%% ortval_test tests ortval().
%
%  Reference:
%
%    Samuel Conte, Carl de Boor,
%    Elementary Numerical Analysis,
%    Third Edition,
%    SIAM, 2017,
%    ISBN: 978-1-611975-19-2.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'ortval_test\n' );
  fprintf ( 1, '  Test ortval()\n' );

  n = 21;
  x = linspace ( -1.0, 1.0, n );
  y = f(x);
  w = ones ( n, 1 );

  nterms = 4;
  [ po, error ] = ortpol ( x, y, w, nterms );

  fprintf ( 1, '\n' );
  fprintf ( 1, '     X      P(X)-F(X)\n' );
  fprintf ( 1, '\n' );
  for i = 1 : n
    fprintf ( 1, '  %8.4f, %e\n', x(i), error(i) );
  end

  fprintf ( 1, '\n' );
  fprintf ( 1, '     Orthogonal polynomial coefficients:\n' );
  fprintf ( 1, '\n' );
  for i = 1 : nterms
    fprintf ( 1, '  %2d  %8.4f\n', i, po.D(i) );
  end

  xp = linspace ( -1.0, 1.0, 31 );
  yp = ortval ( po, xp );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Compare approximating polynomial to f(x):\n' );
  fprintf ( 1, '  x  p(x)  f(x)\n' );
  fprintf ( 1, '\n' );
  for i = 1 : 31
    fprintf ( 1, '  %8.4f  %8.4f  %8.4f\n', xp(i), yp(i), f(xp(i)) );
  end

  return
end
function value = f ( x )

  value = exp ( x );

  return
end

