home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 4.ddi / OPTIM.DI$ / MINIMAX.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  2.5 KB  |  86 lines

  1. function [x,OPTIONS]=minimax(FUN,x,OPTIONS,VLB,VUB,GRADFUN,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10)
  2. %MINIMAX Finds a minimax solution of a function of several variables.
  3. %    MINIMAX solves the following problem:
  4. %    min (max {FUN(X} )  where FUN and X can be vectors or matrices.
  5. %     X 
  6. %    X=MINIMAX('FUN',X0) starts at X0 and finds a minimax solution to 
  7. %    the function which is described in FUN (usually an M-file: FUN.M).
  8. %    The function 'FUN' should return functions to be minimized: F=FUN(X). 
  9. %
  10. %    X=MINIMAX('FUN',X,OPTIONS) allows a vector of optional parameters to 
  11. %    be defined. For more information type HELP FOPTIONS.
  12. %    
  13. %    X=MINIMAX('FUN',X,OPTIONS,VLB,VUB) defines a set of lower and upper
  14. %    bounds on the design variables, X, so that the solution is always in 
  15. %    the range VLB < X < VUB. 
  16. %
  17. %    X=MINIMAX('FUN',X,OPTIONS,VLB,VUB,'GRADFUN') allows a function 
  18. %    'GRADFUN' to be entered which returns the partial derivatives of the 
  19. %    functions at X stored column-wise:  GRADS = GRADFUN(X). 
  20. %
  21. %    X=MINIMAX('FUN',X,OPTIONS,VLB,VUB,GRADFUN,P1,P2,..) allows
  22. %    coefficients, P1, P2, ... to be passed directly to FUN:
  23. %    [F,G]=FUN(X,P1,P2,...). Empty arguments ([]) are ignored. 
  24.  
  25. %    Copyright (c) 1990 by the MathWorks, Inc.
  26. %    Andy Grace 7-9-90.
  27.                      
  28. %
  29.  
  30. if nargin < 3, OPTIONS=[]; end
  31. if nargin < 4, VLB=[]; end
  32. if nargin < 5, VUB=[]; end
  33. if nargin < 6, GRADFUN=[]; end
  34. lenopt = length(OPTIONS); 
  35. if ~lenopt, OPTIONS=0; end
  36.  
  37. xnew=x(:);
  38. OPTIONS=foptions(OPTIONS);
  39. OPTIONS(7) = ~OPTIONS(7);
  40. neqcstr=OPTIONS(15); 
  41.  
  42. if ~any(FUN<48)
  43.     evalstr1 = ['[f,g]=',FUN,];
  44.         evalstr1=[evalstr1, '(x'];
  45.         for i=1:nargin - 6
  46.                 evalstr1 = [evalstr1,',P',int2str(i)];
  47.         end
  48.         evalstr1 = [evalstr1, ');'];
  49. else
  50.         evalstr1=[FUN,';'];
  51. end
  52.  
  53. eval(evalstr1)
  54. ncstr=length(f(:));
  55. WEIGHT = ones(ncstr,1);
  56. GOAL = zeros(ncstr,1);
  57.  
  58. evalstr2='';
  59.  
  60. if length(GRADFUN)
  61.     if ~any(GRADFUN<48) % Check alphanumeric
  62.         evalstr2 = ['[gf,gg]=',GRADFUN,'(x'];
  63.         for i=1:nargin - 6
  64.             evalstr2 = [evalstr2,',P',int2str(i)];
  65.         end
  66.         evalstr2 = [evalstr2, ');'];
  67.         gfun  = 'goalgra';
  68.     else
  69.         evalstr2=[GRADFUN,';'];
  70.     end
  71. else
  72.     gfun = [];
  73. end
  74.  
  75. evalstr = ['[xnew, OPTIONS] = constr(''goalfun'',[xnew;0],OPTIONS,VLB,VUB,gfun,neqcstr,evalstr1,evalstr2,WEIGHT,GOAL,x'];
  76.  
  77. for i=1:nargin - 6
  78.     evalstr = [evalstr,',P',int2str(i)];
  79. end
  80. evalstr = [evalstr, ');'];
  81.  
  82. eval(evalstr)
  83. OPTIONS(7) = ~OPTIONS(7);
  84. x(:) = xnew(1:length(xnew)-1);
  85.