function hex2_gradient2 ( )

%*****************************************************************************80
%
%% hex2_gradient2 uses gradient descent on the hex2 function.
%
%  Discussion:
%
%    Gradient descent for a function of 2 variables.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    02 October 2019
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'hex2_gradient2:\n' );
  fprintf ( 1, '  Seek minimizer of a function z(x,y).\n' );
%
%  Choose a initial guess.
% 
  x0 = [ 2.0, 1.5 ];
%
%  Choose a small learning rate.
%
  r = 0.10;
%
%  Choose a small tolerance for the stepsize.
%
  dxtol = 0.00001;
%
%  Choose a small tolerance for the derivative.
%
  dftol = 0.001;
%
%  Maximum number of iterations
%
  itmax = 100;

  [ x, it ] = gradient_descent2 ( @(x)hex2(x), @(x)hex2_df(x), x0, r, dxtol, dftol, itmax );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  %d gradient descent steps were taken.\n', it );
  fprintf ( 1, '  Initial x,y = (%g,%g),  f(x,y) = %g, f''(x,y) = (%g,%g)\n', ...
    x0, hex2 ( x0 ), hex2_df ( x0 ) )
  fprintf ( 1, '  Final   x,y = (%g,%g),  f(x,y) = %g, f''(x,y) = (%g,%g)\n', ...
    x, hex2 ( x ), hex2_df ( x ) )
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'hex2_gradient2:\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  return
