home *** CD-ROM | disk | FTP | other *** search
- function [x,OPTIONS]=minimax(FUN,x,OPTIONS,VLB,VUB,GRADFUN,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10)
- %MINIMAX Finds a minimax solution of a function of several variables.
- % MINIMAX solves the following problem:
- % min (max {FUN(X} ) where FUN and X can be vectors or matrices.
- % X
- %
- % X=MINIMAX('FUN',X0) starts at X0 and finds a minimax solution to
- % the function which is described in FUN (usually an M-file: FUN.M).
- % The function 'FUN' should return functions to be minimized: F=FUN(X).
- %
- % X=MINIMAX('FUN',X,OPTIONS) allows a vector of optional parameters to
- % be defined. For more information type HELP FOPTIONS.
- %
- % X=MINIMAX('FUN',X,OPTIONS,VLB,VUB) defines a set of lower and upper
- % bounds on the design variables, X, so that the solution is always in
- % the range VLB < X < VUB.
- %
- % X=MINIMAX('FUN',X,OPTIONS,VLB,VUB,'GRADFUN') allows a function
- % 'GRADFUN' to be entered which returns the partial derivatives of the
- % functions at X stored column-wise: GRADS = GRADFUN(X).
- %
- % X=MINIMAX('FUN',X,OPTIONS,VLB,VUB,GRADFUN,P1,P2,..) allows
- % coefficients, P1, P2, ... to be passed directly to FUN:
- % [F,G]=FUN(X,P1,P2,...). Empty arguments ([]) are ignored.
-
- % Copyright (c) 1990 by the MathWorks, Inc.
- % Andy Grace 7-9-90.
-
- %
-
- if nargin < 3, OPTIONS=[]; end
- if nargin < 4, VLB=[]; end
- if nargin < 5, VUB=[]; end
- if nargin < 6, GRADFUN=[]; end
- lenopt = length(OPTIONS);
- if ~lenopt, OPTIONS=0; end
-
- xnew=x(:);
- OPTIONS=foptions(OPTIONS);
- OPTIONS(7) = ~OPTIONS(7);
- neqcstr=OPTIONS(15);
-
- if ~any(FUN<48)
- evalstr1 = ['[f,g]=',FUN,];
- evalstr1=[evalstr1, '(x'];
- for i=1:nargin - 6
- evalstr1 = [evalstr1,',P',int2str(i)];
- end
- evalstr1 = [evalstr1, ');'];
- else
- evalstr1=[FUN,';'];
- end
-
- eval(evalstr1)
- ncstr=length(f(:));
- WEIGHT = ones(ncstr,1);
- GOAL = zeros(ncstr,1);
-
- evalstr2='';
-
- if length(GRADFUN)
- if ~any(GRADFUN<48) % Check alphanumeric
- evalstr2 = ['[gf,gg]=',GRADFUN,'(x'];
- for i=1:nargin - 6
- evalstr2 = [evalstr2,',P',int2str(i)];
- end
- evalstr2 = [evalstr2, ');'];
- gfun = 'goalgra';
- else
- evalstr2=[GRADFUN,';'];
- end
- else
- gfun = [];
- end
-
- evalstr = ['[xnew, OPTIONS] = constr(''goalfun'',[xnew;0],OPTIONS,VLB,VUB,gfun,neqcstr,evalstr1,evalstr2,WEIGHT,GOAL,x'];
-
- for i=1:nargin - 6
- evalstr = [evalstr,',P',int2str(i)];
- end
- evalstr = [evalstr, ');'];
-
- eval(evalstr)
- OPTIONS(7) = ~OPTIONS(7);
- x(:) = xnew(1:length(xnew)-1);
-