by 杨贺宏
function [xmin, ymin] = GlobalNewton( fun, fun1d, fun2d, x1, delta )
% GlobalNewton: Newton method for global minimization
% Input:
% fun: name of the function to minimized
% fun1d: fun'
% fun2d: fun''
% x1: initial point, left bound
% delta: must > 0
% Output:
% xmin:
% ymin:
% check if the input is right.
if( delta <= 0 )
return;
end
xk = x1;
%--------------------------------------------------------------------------
% a technique to avoid using goto.
while 1
%-------------------------------------------------------------------
fun1d_xk = feval( fun1d, xk );
fun2d_xk = feval( fun2d, xk );
%-------------------------------------------------------------------
if fun1d_xk == 0
% if f'( xk ) == 0 and f''( xk ) >= 0, stop.
if fun2d_xk >= 0
xmin = xk
ymin = feval( fun, xk )
return
end
myDelta = delta;
% add this statement because of no do..while loop
myDelta = myDelta / 2.0;
% find the small enough myDelta.
while feval( fun, xk + myDelta ) >= feval( fun, xk )
myDelta = myDelta / 2.0;
end
xk = xk + myDelta;
end
%-------------------------------------------------------------------
fun1d_xk = feval( fun1d, xk );
fun2d_xk = feval( fun2d, xk );
%-------------------------------------------------------------------
if fun1d_xk ~= 0
betaK = fun2d_xk;
if betaK <= 0
betaK = 1;
end
alphaK = 1;
while feval( fun,( xk - alphaK * fun1d_xk / betaK )) > ( feval( fun, xk ) - alphaK / 4.0 * fun1d_xk^2 / betaK )
alphaK = alphaK / 2.0;
end
xk = xk - alphaK * fun1d_xk / betaK;
end
end
%-- while -----------------------------------------------------------------------