function [ xi, fi, n_total ] = interior_point ( m, a, b, f )

%*****************************************************************************80
%
%% INTERIOR_POINT seeks a point X such that F(X) < 0.
%
%  Discussion:
%
%    In a multidimensional space, a surface is describe by F(X) = 0,
%    and the interior of the surface by F(X) < 0.
%
%    We search for a point X in a given hypercube which is an interior point.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer M, the spatial dimension.
%
%    Input, real A(M,1), B(M,1), define opposing vertices of the hypercube.
%
%    Input, function handle F, evaluates the function, having the form
%      v = f ( m, n, x )
%    which returns a vector V(N,1) of function values.
%
%    Output, real XI(M,1), the point where the search stopped.
%
%    Output, real FI, the function value at XI.
%
%    Output, integer N_TOTAL, the total number of points examined.
%
  a = a(:);
  b = b(:);
%
%  Monte Carlo search.
%
  xi = [];
  fi = Inf;
  n_total = 0;

  while ( 1 )

    n = 100;
    x = repmat ( a, 1, n ) + repmat ( b - a, 1, n ) .* rand ( m, n );
    fx = f ( m, n, x );
    [ fx_min, jx_min ] = min ( fx );
%
%  If one of the new values is less than our previous minimum, 
%  save it.
%
    if ( fx_min < fi )
      fi = fx_min;
      xi = x(1:m,jx_min);
    end

    n_total = n_total + n;
%
%  If we found an interior point, we are done.
%
    if ( fi < 0 ) 
      break
    end
%
%  If we took too many steps, we are done.
%
    if ( 10000 < n_total ) 
      break
    end

  end

  return
end
