1 ## Copyright (C) 2003 Andy Adler <adler@ncf.ca>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {[@var{x}] =} fmins(@var{f},@var{X0},@var{options},@var{grad},@var{P1},@var{P2}, ...)
19 ## Find the minimum of a funtion of several variables.
20 ## By default the method used is the Nelder&Mead Simplex algorithm
23 ## fmins(inline('(x(1)-5).^2+(x(2)-8).^4'),[0;0])
28 ## A string containing the name of the function to minimize
30 ## A vector of initial parameters fo the function @var{f}.
32 ## Vector with control parameters (not all parameters are used)
34 ## options(1) - Show progress (if 1, default is 0, no progress)
35 ## options(2) - Relative size of simplex (default 1e-3)
36 ## options(6) - Optimization algorithm
37 ## if options(6)==0 - Nelder & Mead simplex (default)
38 ## if options(6)==1 - Multidirectional search Method
39 ## if options(6)==2 - Alternating Directions search
41 ## if options(6)==0 && options(5)==0 - regular simplex
42 ## if options(6)==0 && options(5)==1 - right-angled simplex
43 ## Comment: the default is set to "right-angled simplex".
44 ## this works better for me on a broad range of problems,
45 ## although the default in nmsmax is "regular simplex"
46 ## options(10) - Maximum number of function evaluations
49 ## Unused (For compatibility with Matlab)
51 ## Optional parameters for function @var{f}
56 function ret=fmins(funfun, X0, options, grad, varargin)
57 stopit = [1e-3, inf, inf, 1, 0, -1];
60 if nargin < 3; options=[]; end
62 if length(options)>=1; stopit(5)= options(1); end
63 if length(options)>=2; stopit(1)= options(2); end
64 if length(options)>=5;
65 if options(6)==0; minfun= 'nmsmax';
66 if options(5)==0; stopit(4)= 0;
67 elseif options(5)==1; stopit(4)= 1;
68 else error('options(5): no associated simple strategy');
70 elseif options(6)==1; minfun= 'mdsmax';
71 elseif options(6)==2; minfun= 'adsmax';
72 else error('options(6) does not correspond to known algorithm');
75 if length(options)>=10; stopit(2)= options(10); end
77 ret = feval(minfun, funfun, X0, stopit, [], varargin{:});