function interp_chebyshev_test ( )

%*****************************************************************************80
%
%% interp_chebyshev_test() tests interp_chebyshev().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    29 June 2019
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Kendall Atkinson, Weimin Han,
%    Elementary Numerical Analysis,
%    Wiley, 2004,
%    ISBN: 0471433373,
%    LC: QA297.A83.2004.
%
  addpath ( '../interp_chebyshev' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'interp_chebyshev_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Test interp_chebyshev():\n' );

  a = 0.0;
  b = 2.0;
  n = 11;
  [ xp, yp ] = interp_chebyshev ( 'humps_fun(x)', a, b, n );

  x = chebyspace ( a, b, n );
  y = humps_fun ( x );

  yt = humps_fun ( xp );

  clf ( );
  hold ( 'on' );
  plot ( xp, yt, 'b-', 'linewidth', 3 );
  plot ( xp, yp, 'r-', 'linewidth', 3 );
  plot ( x, y, '.', 'markersize', 25 );
  legend ( 'True function', 'Interpolant', 'Data' );
  grid ( 'on' );
  hold ( 'off' );
  filename = 'humps_chebyshev.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
  pause ( 5.0 )
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'interp_chebyshev_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  timestamp ( );

  rmpath ( '../interp_chebyshev' );

  return
end
function x = chebyspace ( a, b, n )

%*****************************************************************************80
%
%% chebyspace creates a vector of Chebyshev spaced values.
%
%  Discussion:
%
%    A set of points with Chebyshev spacing is generated for the
%    interval [A,B].
%
%    An R8VEC is a vector of R8's.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    08 June 2011
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the number of entries in the vector.
%
%    real A, B, the interval endpoints.
%
%  Output:
%
%    real X(N,1), a vector of Chebyshev spaced data.
%
  x = zeros ( n, 1 );

  if ( n == 1 )

    x(1) = ( a + b ) / 2.0;

  else

    for i = 1 : n

      theta = ( n - i ) * pi / ( n - 1 );

      c = cos ( theta );

      if ( mod ( n, 2 ) == 1 )
        if ( 2 * i - 1 == n )
          c = 0.0;
        end
      end

      x(i) = ( ( 1.0 - c ) * a  ...
             + ( 1.0 + c ) * b ) ...
             /   2.0;

    end

  end

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the current YMDHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
  t = now;
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end

