function f = p36_f ( n, x )

%*****************************************************************************80
%
%% p36_f() evaluates the objective function for problem 36.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    16 October 2004
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Zbigniew Michalewicz,
%    Genetic Algorithms + Data Structures = Evolution Programs,
%    Third Edition,
%    Springer Verlag, 1996,
%    ISBN: 3-540-60676-9,
%    LC: QA76.618.M53.
%
%  Input:
%
%    integer N, the number of variables.
%
%    real X(N), the argument of the objective function.
%
%  Output:
%
%    real F, the value of the objective function.
%
  [ b, m1, m2, r11, r12, r21, r22 ] = p36_p_get ( );

  a1 = floor ( abs ( x(1) - r11 ) ) + floor ( abs ( x(2) - r21 ) );

  a2 = floor ( abs ( x(1) - r12 ) ) + floor ( abs ( x(2) - r22 ) );

  if ( x(1) <= b )
    if ( a1 == 0.0 )
      f = floor ( m1 );
    else
      f = floor ( m1 * sin ( a1 ) / a1 );
    end
  else
    if ( a2 == 0.0 )
      f = floor ( m2 );
    else
      f = floor ( m2 * sin ( a2 ) / a2 );
    end
  end

  return
end
