function gradient_descent_data_fitting_test ( )

%*****************************************************************************80
%
%% gradient_descent_data_fitting_test() tests gradient_descent_data_fitting().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    30 July 2022
%
%  Author:
%
%    John Burkardt.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'gradient_descent_data_fitting_test():\n' );
  fprintf ( 1, '  gradient_descent_data_fitting() approximates the solution\n' );
  fprintf ( 1, '  of a data fitting problem using gradient descent.\n' );

  A = [ ...
    1998,   27000,     9991; ... 
    1997,   17000,     9925; ... 
    1998,   28000,    10491; ... 
    1998,    5000,    10990; ... 
    1997,   38000,     9493; ... 
    1997,   36000,     9991; ... 
    1997,   24000,    10490; ... 
    1997,   37000,     9491; ... 
    1997,   38000,     9491; ... 
    1997,   30000,     9990; ... 
    1997,   38000,     9491; ... 
    1997,   25000,     9990; ... 
    1997,   39000,     9990; ... 
    1997,   22000,     9390; ... 
    1997,   24000,     9990; ... 
    1997,   37000,     9990; ... 
    1997,   29000,     9990; ... 
    1997,   70000,     8990; ... 
    1996,   29000,     7990; ... 
    1995,   72000,     5994; ... 
    1993,   72000,     5994; ...
    1994,   61000,     5500; ...
    1998,    7000,    11000 ];

  x = A(:,2);
  y = A(:,3);
  xmin = min ( x );
  xmax = max ( x );
  x = ( x - xmin ) / ( xmax - xmin );
  ymin = min ( y );
  ymax = max ( y );
  y = ( y - ymin ) / ( ymax - ymin );
  m = length ( x );
  x = [ ones(m,1), x ];

  it_max = 100;
  alpha = 0.03;
  tol = 1.0e-3;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Maximum iterations = %d\n', it_max );
  fprintf ( 1, '  Learning rate = %g\n', alpha );
  fprintf ( 1, '  Stepsize tolerance = %g\n', tol );

  [ c, it ] = gradient_descent_data_fitting ( x, y, it_max, alpha, tol );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Number of iterations = %d\n', it );
  disp ( '  Estimated solution:' );
  disp ( c );

  return
end

