]> Creatis software - CreaPhase.git/blob - octave_packages/optim-1.2.0/__semi_bracket.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / optim-1.2.0 / __semi_bracket.m
1 ## Copyright (C) 2002 Etienne Grossmann <etienne@egdn.net>
2 ## Copyright (C) 2009 Levente Torok <TorokLev@gmail.com>
3 ##
4 ## This program is free software; you can redistribute it and/or modify it under
5 ## the terms of the GNU General Public License as published by the Free Software
6 ## Foundation; either version 3 of the License, or (at your option) any later
7 ## version.
8 ##
9 ## This program is distributed in the hope that it will be useful, but WITHOUT
10 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12 ## details.
13 ##
14 ## You should have received a copy of the GNU General Public License along with
15 ## this program; if not, see <http://www.gnu.org/licenses/>.
16
17 ## [a, b, ga, gb, nev] = semi_bracket (f, dx, a, narg, args)
18 ##
19 ## Find an interval containing a local minimum of the function 
20 ## g : h in [a, inf[ ---> f (x+h*dx) where x = args{narg}
21 ##
22 ## The local minimum may be in a.
23 ## a < b.
24 ## nev is the number of function evaluations.
25
26 function [a,b,ga,gb,n] = __semi_bracket (f, dx, a, narg, args)
27
28 step = 1;
29
30 x = args{narg};
31 args{narg} =  x+a*dx; ga = feval (f, args );
32 b = a + step;
33 args{narg} =  x+b*dx; gb = feval (f, args );
34 n = 2;
35
36 if gb >= ga, return ; end
37
38 while 1,
39
40   c = b + step;
41   args{narg} = x+c*dx; gc = feval( f, args );
42   n++;
43
44   if gc >= gb,                  # ga >= gb <= gc
45     gb = gc; b = c;
46     return;
47   end
48   step *= 2;
49   a = b; b = c; ga = gb; gb = gc;
50 end