function approx_leastsquares_test ( )

%*****************************************************************************80
%
%% approx_leastsquares_test() tests approx_leastsquares().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    11 August 2019
%
%  Author:
%
%    John Burkardt
%
  addpath ( '../approx_leastsquares' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'approx_leastsquares_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Test approx_leastsquares().\n' );

  a = 0.0;
  b = 2.0;

  np = 101;
  xp = linspace ( a, b, np );
  xp = xp';
  fp = humps_fun ( xp );

  fprintf ( 1, '\n' );
  fprintf ( 1, '    M    N     RMSerr\n' );
  fprintf ( 1, '\n' );
  n = 3;
  for k = 0 : 10
    m = k;
    [ xp, yp, rmserr ] = approx_leastsquares ( 'humps_fun(x)', a, b, m, n );
    fprintf ( '  %3d  %3d  %14.6g\n', m, n, rmserr );
    n = 2 * ( n - 1 ) + 1;
  end

  n = 3;
  for k = 0 : 10
    m = k;
    [ xp, yp, rmserr ] = approx_leastsquares ( 'humps_fun(x)', a, b, m, n );
    clf ( );
    hold ( 'on' );
    plot ( xp, fp, 'b-', 'linewidth', 3 );
    plot ( xp, yp, 'r-', 'linewidth', 3 );
    label = sprintf ( 'Degree %d Least Squares, %d data values', m, n );
    title ( label, 'fontsize', 16 );
    grid ( 'on' );
    hold ( 'off' )
    pause ( 4.0 )
    n = 2 * ( n - 1 ) + 1;
  end

  filename = 'humps_leastsquares.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'approx_leastsquares_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  timestamp ( );

  rmpath ( '../approx_leastsquares' );

  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
 
