function value = beale_f ( x, n )

%*****************************************************************************80
%
%% BEALE_F evaluates the Beale function.
%
%  Discussion:
%
%    The function is the sum of the squares of three functions.
%
%    This function has a valley approaching the line X(2) = 1.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    30 July 2016
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    E Beale,
%    On an Iterative Method for Finding a Local Minimum of a Function
%    of More than One Variable,
%    Technical Report 25, Statistical Techniques Research Group,
%    Princeton University, 1958.
%
%    Richard Brent,
%    Algorithms for Finding Zeros and Extrema of Functions Without
%    Calculating Derivatives,
%    Stanford University Technical Report STAN-CS-71-198.
%
%  Parameters:
%
%    Input, real X(N), the evaluation point.
%
%    Input, integer N, the number of variables.
%
%    Output, real VALUE, the function value.
%
  c1 = 1.5;
  c2 = 2.25;
  c3 = 2.625;

  fx1 = c1 - x(1) * ( 1.0 - x(2)     );
  fx2 = c2 - x(1) * ( 1.0 - x(2) ^ 2 );
  fx3 = c3 - x(1) * ( 1.0 - x(2) ^ 3 );

  value = fx1 ^ 2 + fx2 ^ 2 + fx3 ^ 2;

  return
end
