function x = gradient_descent_nonlinear ( f, df, x, it_max, alpha )

%*****************************************************************************80
%
%% gradient_descent_nonlinear(): gradient descent for scalar nonlinear f(x).
%
%  Discusssion:
%
%    We are given a scalar nonlinear function f(x) and want to estimate
%    the location of a local minimizer.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    27 July 2022
%
%  Author:
%
%    John Burkardt.
%
%  Input:
%
%    real value = F(X): evaluates the function.
%
%    real value = DF(X): evaluates the derivative of the function.
%
%    real X: the initial guess for the minimizer.
%
%    integer IT_MAX: the maximum number of steps.
%
%    real ALPHA: the learning rate.
%
%  Output:
%
%    real X: the estimated minimizer.
%
  print_out = true;

  if ( print_out )
    fprintf ( 1, '\n' )
    fprintf ( 1, '   it      x               f(x)         f''(x)\n' )
    fprintf ( 1, '\n' )
  end

  for it = 0 : it_max

    if ( 0 < it )
      xold = x;
      x = x - alpha * df ( x ) * f ( x );
    end

    if ( print_out )
      fprintf ( 1, '  %3d  %12.8g  %12.8g  %12.8g\n', it, x, f ( x ), df ( x ) )
    end

  end

  return
end


