function gdif = p00_gdif ( problem, n, x )

%*****************************************************************************80
%
%% p00_gdif() approximates the gradient via finite differences.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    16 October 2011
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer PROBLEM, the problem number.
%
%    integer N, the number of variables.
%
%    real X(N), the point where the gradient
%    is to be approximated.
%
%  Output:
%
%    real GDIF(N), the approximated gradient vector.
%
  xrel = sqrt ( eps );

  for i = 1 : n

    if ( 0.0 <= x(i) )
      dx = xrel * ( x(i) + 1.0 );
    else
      dx = xrel * ( x(i) - 1.0 );
    end

    xi = x(i);
    x(i) = xi + dx;
    fplus = p00_f ( problem, n, x );

    x(i) = xi - dx;
    fminus = p00_f ( problem, n, x );

    gdif(i) = ( fplus - fminus ) / ( 2.0 * dx );

    x(i) = xi;

  end

  return
end
