Graphics Programs Reference
In-Depth Information
which yields
ln(
ε/ |
b
a
|
)
ε
n
=
=−
2
.
078 087 ln
(10.4)
|
|
ln R
b
a
goldBracket
Thisfunction contains the bracketing algorithm. For the factor that multiplies suc-
cessivesearch intervals we chose c
=
1
+
R .
function [a,b] = goldBracket(func,x1,h)
% Brackets the minimum point of f(x).
% USAGE: [a,b] = goldBracket(func,xStart,h)
% INPUT:
% func
= handle of function that returns f(x).
% x1
= starting value of x.
% h
= initial step size used in search.
% OUTPUT:
%a,b=limitsonxattheminimumpoint.
c = 1.618033989;
f1 = feval(func,x1);
x2 = x1 + h; f2 = feval(func,x2);
% Determine downhill direction & change sign of h if needed.
iff2>f1
h=-h;
x2 = x1 + h; f2 = feval(func,x2);
%Checkifminimumisbetweenx1-handx1+h
iff2>f1
a=x2;b=x1-h;return
end
end
% Search loop
fori=1:100
h=c*h;
x3 = x2 + h; f3 = feval(func,x3);
iff3>f2
a=x1;b=x3;return
end
x1=x2;f1=f2;x2=x3;f2=f3;
end
error('goldbracket did not find minimum')
Search WWH ::




Custom Search