optimize

PURPOSE ^

OPTIMIZE Optimize general constrained problems using Nelder-Mead algorithm

SYNOPSIS ^

function [sol, fval, exitflag, output] =optimize(funfcn, x0, lb, ub, A, b, Aeq, beq, nonlcon,strictness, options, algorithm, varargin)

DESCRIPTION ^

OPTIMIZE        Optimize general constrained problems using Nelder-Mead algorithm

 Usage:
 sol = OPTIMIZE(func, x0) 
 sol = OPTIMIZE(..., x0, lb, ub)
 sol = OPTIMIZE(..., ub, A, b) 
 sol = OPTIMIZE(..., b, Aeq, beq) 
 sol = OPTIMIZE(..., beq, nonlcon) 
 sol = OPTIMIZE(..., nonlcon, strictness) 
 sol = OPTIMIZE(..., strictness, options) 
 sol = OPTIMIZE(..., options, algorithm) 

 [sol, fval] = OPTIMIZE(func, ...)
 [sol, fval, exitflag] = OPTIMIZE(func, ...)
 [sol, fval, exitflag, output] = OPTIMIZE(func, ...)

 INPUT ARGUMENTS:

  fun, x0, options, varargin - see the help for FMINSEARCH.

  lb - (OPTIONAL) lower bound vector or array, must have the same 
       size as x0.

       If no lower bounds exist for one of the variables, then
       supply -inf for that variable.

       If no lower bounds exist at all, then [lb] may be left empty.

       Variables may be fixed in value by setting the corresponding
       lower and upper bounds to exactly the same value.

  ub - (OPTIONAL) upper bound vector or array, must have the same 
       size as x0.

       If no upper bounds exist for one of the variables, then
       supply +inf for that variable.

       If no upper bounds at all, then [ub] may be left empty.

       Variables may be fixed in value by setting the corresponding
       lower and upper bounds to exactly the same value.

  A, b - (OPTIONAL) Linear inequality constraint array and right
       hand side vector. (Note: these constraints were chosen to
       be consistent with those of fmincon.)

       This linear constraint forces the solution vector [x] to 
       satisfy 
                               A*x <= b

       Note that in case [x] is a matrix (this is true when [x0] is
       a matrix), the argument [b] must have corresponding size 
       [size(A,1) x size(x0,2)], since the same equation is used to 
       evaluate this constraint. 

  Aeq, beq - (OPTIONAL) Linear equality constraint array and right
       hand side vector. (Note: these constraints were chosen to
       be consistent with those of fmincon.)

       This linear constraint forces the solution vector [x] to 
       satisfy 

                               Aeq*x == beq

       Note that in case [x] is a matrix (this is true when [x0] is
       a matrix), the argument [beq] must have corresponding size 
       [size(Aeq,1) x size(x0,2)], since the same equation is used to 
       evaluate this constraint.

  nonlcon - (OPTIONAL) function handle to general nonlinear constraints,
       inequality and/or equality constraints.

       [nonlcon] must return two vectors, [c] and [ceq], containing the
       values for the nonlinear inequality constraints [c] and
       those for the nonlinear equality constraints [ceq] at [x]. (Note: 
       these constraints were chosen to be consistent with those of 
       fmincon.)

       These constraints force the solution to satisfy

               ceq(x)  = 0
                 c(x) <= 0,

       where [c(x)] and [ceq(x)] are general non-linear functions of [x].

 strictness - (OPTIONAL) By default, OPTIMIZE will assume the objective 
       (and constraint) function(s) can be evaluated at ANY point in 
       RN-space; the initial estimate does not have to lie in the 
       feasible region, and intermediate solutions are also allowed to step 
       outside this area. If your function does not permit such behavior, 
       set this argument to 'strict'. With 'strict' enabled, the linear 
       constraints will be satisfied strictly, while the nonlinear 
       constraints will be satisfied within options.TolCon. 

       If this is also not permissible, use 'superstrict' - then all 
       nonlinear constraints are also satisfied AT ALL TIMES, and the 
       objective function is NEVER evaluated outside the feasible area. 

       When using 'strict' or 'superstrict', the initial estimate [x0]
       MUST be feasible. If it is not feasible, an error is produced
       before the objective function is ever evaluated. 

 algorithm - (OPTIONAL) By default, an embedded version of the 
       Nelder-Mead algorithm is used. This version is slightly more 
       robust and internally effecient than the one implemented in 
       FMINSEARCH. The FMINSEARCH algorithm can still be selected, by
       setting [algorithm] to 'fminsearch'. 


 OUTPUT ARGUMENTS:

 sol, fval - the solution vector and the corresponding function value,
       respectively. 

 exitflag - (See also the help on FMINSEARCH) A flag that specifies the
       reason the algorithm terminated. FMINSEARCH uses only the values

           1    fminsearch converged to a solution x
           0    Max. # of function evaluations or iterations exceeded
          -1    Algorithm was terminated by the output function.

       Since OPTIMIZE handles constrained problems, the following two
       values were added:

           2    All elements in [lb] and [ub] were equal - nothing done
          -2    Problem is infeasible after the optimization (Some or
                any of the constraints are violated at the final
                solution).
          -3    INF or NAN encountered during the optimization.

 output - (See also the help on FMINSEARCH) A structure that contains
       additional details on the optimization. FMINSEARCH returns

           output.algorithm   Algorithm used
           output.funcCount   Number of function evaluations
           output.iterations  Number of iterations
           output.message     Exit message

       Since OPTIMIZE handles constrained problems, the following
       fields were added:

           output.constrviolation.lin_ineq
           output.constrviolation.lin_eq
           output.constrviolation.nonlin_ineq
           output.constrviolation.nonlin_ineq

       All these fields contain a [M x 2]-cell array. The fist column
       contains a logical index to the constraints, which is true if the
       constraint was violated, false if it was satisfied. The second
       column contains the amount of constraint violation. This amount is
       equal to zero if the constraint was satisfied within
       options.TolCon.


 Notes:

  If options is supplied, then TolX will apply to the transformed
  variables. All other FMINSEARCH parameters should be unaffected.

  Variables which are constrained by both a lower and an upper
  bound will use a sin() transformation. Those constrained by
  only a lower or an upper bound will use a quadratic
  transformation, and unconstrained variables will be left alone.

  Variables may be fixed by setting their respective bounds equal.
  In this case, the problem will be reduced in size for FMINSEARCH.

  If your problem has an EXCLUSIVE (strict) bound constraints which
  will not permit evaluation at the bound itself, then you must
  provide a slightly offset bound. An example of this is a function
  which contains the log of one of its parameters. If you constrain
  the variable to have a lower bound of zero, then OPTIMIZE may
  try to evaluate the function exactly at zero.

 EXAMPLES:

 rosen = @(x) (1-x(1)).^2 + 105*(x(2)-x(1).^2).^2;

 <<Fully unconstrained problem>>

 optimize(rosen, [3 3])
 ans =
    1.0000    1.0000


 <<lower bound constrained>>

 optimize(rosen,[3 3],[2 2],[])
 ans =
    2.0000    4.0000


 <<x(2) fixed at 3>>

 optimize(rosen,[3 3],[-inf 3],[inf,3])
 ans =
    1.7314    3.0000


 <<simple linear inequality: x(1) + x(2) <= 1>>

 optimize(rosen,[0 0],[],[],[1 1], 1)

 ans =
    0.6187    0.3813


 <<nonlinear inequality: sqrt(x(1)^2 + x(2)^2) <= 1>>
 <<nonlinear equality  : x(1)^2 + x(2)^3 = 0.5>>

 execute this m-file:

   function test_optimize
        rosen = @(x) (1-x(1)).^2 + 105*(x(2)-x(1).^2).^2;

        options = optimset('TolFun', 1e-8, 'TolX', 1e-8);

        optimize(rosen, [3 3], [],[],[],[],[],[],...
        @nonlcon, [], options)

   end
   function [c, ceq] = nonlcon(x)
        c = norm(x) - 1;
        ceq = x(1)^2 + x(2)^3 - 0.5;
   end

 ans =
    0.6513    0.4233



 Of course, any combination of the above constraints is
 also possible.


 See also: fminsearch, fminsearchcon, fminsearchbnd, fmincon.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:
Generated on Fri 21-Sep-2012 09:46:34 by m2html © 2005