function [limits] = find_limits(function, E, near)

% limits(FUNCTION, VALUE, NEAR) returns the value X0 for which the minimum
%   of FUNCTION(X0,Y) minimized over values of Y equals VALUE.  More
%   simply, it finds the "edge" of FUNCTION(X,Y)==VALUE in X.  The value of
%   X is found near NEAR.
%
% If VALUE is a vector, the result is a vector whose elements are each
%   equal to limits(FUNCTION, VALUE(i), NEAR).
%
% limits(FUNCTION, VALUE, [LOW HIGH]) finds values between LOW and HIGH.

cntr = inline('feval(f,fmin(f,-1000,1000,[],b),b)-v', 'b','f','v');

for i = 1:length(E),
  E(i)
  limits(i) = fzero(cntr, near, [],[], function,E(i));
end
