]> Creatis software - CreaPhase.git/blob - octave_packages/optim-1.2.0/fmins.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / optim-1.2.0 / fmins.m
1 ## Copyright (C) 2003 Andy Adler <adler@ncf.ca>
2 ##
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
6 ## version.
7 ##
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
11 ## details.
12 ##
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/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function File} {[@var{x}] =} fmins(@var{f},@var{X0},@var{options},@var{grad},@var{P1},@var{P2}, ...)
18 ## 
19 ## Find the minimum of a funtion of several variables.
20 ## By default the method used is the Nelder&Mead Simplex algorithm
21 ##
22 ## Example usage:
23 ##   fmins(inline('(x(1)-5).^2+(x(2)-8).^4'),[0;0])
24 ## 
25 ## @strong{Inputs}
26 ## @table @var 
27 ## @item f 
28 ## A string containing the name of the function to minimize
29 ## @item X0
30 ## A vector of initial parameters fo the function @var{f}.
31 ## @item options
32 ## Vector with control parameters (not all parameters are used)
33 ## @verbatim
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
40 ## options(5)
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
47 ## @end verbatim
48 ## @item grad
49 ## Unused (For compatibility with Matlab)
50 ## @item P1,P2, ...
51 ## Optional parameters for function @var{f} 
52 ##
53 ## @end table
54 ## @end deftypefn
55
56 function ret=fmins(funfun, X0, options, grad, varargin)
57     stopit = [1e-3, inf, inf, 1, 0, -1];
58     minfun = 'nmsmax'; 
59
60     if nargin < 3; options=[]; end
61
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');
69             end
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');
73         end
74     end
75     if length(options)>=10; stopit(2)= options(10); end
76
77     ret = feval(minfun, funfun,  X0, stopit, [], varargin{:});
78 endfunction