1、MATLAB优化工具Find minimum of constrained nonlinear multivariable functionEquationFinds the minimum of a problem specified byb and beq are vectors, A and Aeq are matrices, c(x) and ceq(x) are functions that return vectors, and f(x) is a function that returns a scalar. f(x), c(x),and ceq(x) can be nonlin
2、ear functions.x, lb, and ub can be passed as vectors or matrices; see Matrix Arguments.Syntaxx = fmincon(fun,x0,A,b)x = fmincon(fun,x0,A,b,Aeq,beq)x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub)x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon)x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)x = fmincon(proble
3、m)x,fval = fmincon(.)x,fval,exitflag = fmincon(.)x,fval,exitflag,output = fmincon(.)x,fval,exitflag,output,lambda = fmincon(.)x,fval,exitflag,output,lambda,grad= fmincon(.)x,fval,exitflag,output,lambda,grad,hessian= fmincon(.)Descriptionfmincon attempts to find a constrained minimum of a scalar func
4、tion of several variables starting at an initial estimate.This is generally referred to as constrained nonlinear optimization or nonlinear programming.Note:Passing Extra Parameters explains how to pass extra parameters to the objective function and nonlinear constraint functions, if necessary.x = fm
5、incon(fun,x0,A,b) starts at x0 and attempts to find a minimizer x of the function described in fun subject to the linearinequalities A*xb. x0 canbe a scalar, vector, or matrix.x = fmincon(fun,x0,A,b,Aeq,beq) minimizes fun subjectto the linear equalities Aeq*x=beq and A*xb. If no inequalitiesexist, s
6、et A = and b = .x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub) definesa set of lower and upper bounds on the design variables in x,so that the solution is always in the range lbxub.If no equalities exist, set Aeq = and beq= . If x(i) is unbounded below, set lb(i)= -Inf, and if x(i) is unbounded above,set ub(
7、i) = Inf.Note:If the specified input bounds for a problem are inconsistent,the output x is x0 and the output fval is .Components of x0 that violate the bounds lbxub are reset to the interior of the box definedby the bounds. Components that respect the bounds are not changed.See Iterations Can Violat
8、e Constraints.x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon) subjectsthe minimization to the nonlinear inequalities c(x) orequalities ceq(x) defined in nonlcon. fmincon optimizessuch that c(x)0 and ceq(x)=0. If no bounds exist, set lb= and/or ub = .x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options
9、) minimizeswith the optimization options specified in options.Use optimoptions to set theseoptions. If there are no nonlinear inequality or equality constraints,set nonlcon = .x = fmincon(problem) finds the minimumfor problem, where problem isa structure described in Input Arguments. Create the prob
10、lem structure by exporting a problem from Optimization app, as described in Exporting Your Work.x,fval = fmincon(.) returns the value of the objective function fun at the solution x.x,fval,exitflag = fmincon(.) returns a value exitflag that describes the exit condition of fmincon.x,fval,exitflag,out
11、put = fmincon(.) returns a structure output with information about the optimization.x,fval,exitflag,output,lambda = fmincon(.) returns a structure lambda whose fields contain the Lagrange multipliers at the solution x.x,fval,exitflag,output,lambda,grad= fmincon(.) returns the value of the gradient o
12、f fun atthe solution x.x,fval,exitflag,output,lambda,grad,hessian= fmincon(.) returns the value of the Hessian at thesolution x. See fmincon Hessian.Input ArgumentsFunction Arguments describes the arguments passed to fmincon. Options provides the function-specific details for the options values. Thi
13、s section provides function-specific details for fun, nonlcon,and problem.FunThe function to be minimized. fun is a function that accepts a vector x and returns a scalar f, the objective function evaluated at x. fun can be specified as a function handle for a file:x = fmincon(myfun,x0,A,b)where myfu
14、n is a MATLAB function such asfunction f = myfun(x)f = . % Compute function value at xfun can also be a function handle for an anonymous function:x = fmincon(x)norm(x)2,x0,A,b);If the gradient of fun can also be computed and the GradObj option is on, as set byoptions = optimoptions(fmincon,GradObj,o
15、n)then fun must return the gradient vector g(x) in the second output argument.If the Hessian matrix can also be computed and the Hessian option is on via options=optimoptions (fmincon,Hessian,user-supplied) and the Algorithm option is trust-region-reflective, fun must return the Hessian value H(x),
16、a symmetric matrix, in a third output argument. fun can give a sparse Hessian. See Writing Objective Functions for details.If the Hessian matrix can be computed and the Algorithm option is interior-point, there are several ways to pass the Hessian to fmincon. For more information,see Hessian.A, b, A
17、eq, beqLinear constraint matrices A and Aeq, and their corresponding vectors b and beq, can be sparse or dense. The trust-region-reflective and interior-point algorithms use sparse linear algebra. If A or Aeq is large, with relatively few nonzero entries, save running time and memory in the trust-re
18、gion-reflective or interior-point algorithms by using sparse matrices. NonlconThe function that computes the nonlinear inequality constraints c(x) 0 and the nonlinear equality constraints ceq(x) = 0. nonlcon accepts a vector x and returns the two vectors c and ceq. c is a vector that contains the no
19、nlinear inequalities evaluated at x, and ceq is a vector that contains the nonlinear equalities evaluated at x. nonlcon should be specified as a function handle to a file or to an anonymous function,such as mycon:x = fmincon(myfun,x0,A,b,Aeq,beq,lb,ub,mycon)where mycon is a MATLAB function such asfu
20、nction c,ceq = mycon(x)c = . % Compute nonlinear inequalities at x.ceq = . % Compute nonlinear equalities at x.If the gradients of the constraints can also be computed and the GradConstr option is on, as set byoptions = optimoptions (fmincon,GradConstr,on) then nonlcon must also return, in the third
21、 and fourth output arguments, GC, the gradient of c(x), and GCeq, the gradient of ceq(x). GC and GCeq can be sparse or dense. If GC or GCeq is large, with relatively few nonzero entries, save running time and memory in the interior-point algorithm by representing them as sparse matrices. For more in
22、formation, see Nonlinear Constraints.NoteBecause Optimization Toolbox functions only accept inputs of type double, user-supplied objective and nonlinear constraint functions must return outputs of type double. Problemobjective Objective functionx0 Initial point for xAineq Matrix for linear inequalit
23、y constraintsbineq Vector for linear inequality constraintsAeq Matrix for linear equality constraintsbeq Vector for linear equality constraintslbVector of lower boundsubVector of upper boundsnonlcon Nonlinear constraint functionsolver fminconoptions Options created with optimoptionsOutput ArgumentsF
24、unction Arguments describes arguments returned by fmincon. This section provides function-specific details for exitflag, lambda, and output: ExitflagInteger identifying the reason the algorithm terminated. The following lists the values of exitflag and the corresponding reasons the algorithm termina
25、ted. All Algorithms:1 First-order optimality measure was less than options.TolFun, and maximum constraint violation was less than options.TolCon.0 Number of iterations exceeded options.MaxIter or number of function evaluations exceeded options.MaxFunEvals.-1 Stopped by an output function or plot fun
26、ction.-2 No feasible point was found.trust-region-reflective, interior-point, and sqp algorithms:2 Change in x was less than options.TolX and maximum constraint violation was less than options.TolCon.trust-region-reflective algorithm only:3 Change in the objective function value was less than option
27、s.TolFun and maximum constraint violation was less than options.TolCon.active-set algorithm only:4 Magnitude of the search direction was less than 2*options.TolX and maximum constraint violation was less than options.TolCon.5 Magnitude of directional derivative in search direction was less than 2*op
28、tions.TolFun and maximum constraint violation was less than options.TolCon.interior-point and sqp algorithms:-3 Objective function at current iteration went below options.ObjectiveLimit and maximum constraint violation was less than options.TolCon.Grad Gradient at xHessian Hessian at xLambda Structu
29、re containing the Lagrange multipliers at the solution x (separated by constraint type). The fields of the structure are:Lower Lower bounds lbUpper Upper bounds ubIneqlin Linear inequalitieseqlinLinear equalitiesineqnonlin Nonlinear inequalitieseqnonlin Nonlinear equalitiesoutput Structure containin
30、g information about the optimization. The fields of the structure are:iterations Number of iterations takenfuncCount Number of function evaluationslssteplength Size of line search step relative to search direction (active-set algorithm only)constrviolation Maximum of constraint functionsstepsize Len
31、gth of last displacement in x (active-set and interior-point algorithms)algorithm Optimization algorithm usedcgiterations Total number of PCG iterations (trust-region-reflective and interior-point algorithms)firstorderopt Measure of first-order optimality message Exit messageHessianfmincon uses a Hessian as an optional input. This Hessian is the second derivatives of the Lagrangian (see Equation3-1), namely,The various fmincon algorithms handle input Hessians differently:The active-set and sqp algorithms do not accept a user-supplied Hessian. They compute a quasi-Newton ap
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1