X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Foptim-1.2.0%2F__semi_bracket.m;fp=octave_packages%2Foptim-1.2.0%2F__semi_bracket.m;h=65a765b2f0e395b2c2d78dbe83a3f64ff9903fe7;hp=0000000000000000000000000000000000000000;hb=c880e8788dfc484bf23ce13fa2787f2c6bca4863;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/optim-1.2.0/__semi_bracket.m b/octave_packages/optim-1.2.0/__semi_bracket.m new file mode 100644 index 0000000..65a765b --- /dev/null +++ b/octave_packages/optim-1.2.0/__semi_bracket.m @@ -0,0 +1,50 @@ +## Copyright (C) 2002 Etienne Grossmann +## Copyright (C) 2009 Levente Torok +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see . + +## [a, b, ga, gb, nev] = semi_bracket (f, dx, a, narg, args) +## +## Find an interval containing a local minimum of the function +## g : h in [a, inf[ ---> f (x+h*dx) where x = args{narg} +## +## The local minimum may be in a. +## a < b. +## nev is the number of function evaluations. + +function [a,b,ga,gb,n] = __semi_bracket (f, dx, a, narg, args) + +step = 1; + +x = args{narg}; +args{narg} = x+a*dx; ga = feval (f, args ); +b = a + step; +args{narg} = x+b*dx; gb = feval (f, args ); +n = 2; + +if gb >= ga, return ; end + +while 1, + + c = b + step; + args{narg} = x+c*dx; gc = feval( f, args ); + n++; + + if gc >= gb, # ga >= gb <= gc + gb = gc; b = c; + return; + end + step *= 2; + a = b; b = c; ga = gb; gb = gc; +end