matlab 参数优化函数,MATLAB优化函数fmincon解析

MATLAB,优化函数fmincon解析

[x,fval,exitflag,output,lambda,grad,hessian]=fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options);

输入参数:fun要求解的函数值;x0函数fun参数值的初始化;

参数值的线性不等式约束A,b

参数值的等式线性约束Aeq,beq,

参数值的上界和下界lb,ub

非线性约束nonlcon

0c45e81eddd665da6d86ce72a0289cf7.png                 e34f6ba8f153e9526947b45f6edf245f.png

输出参数:X输出最优参数值

Fval输出fun在X参数的值

Exitflag输出fmincon额外条件值

function [X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = fmincon(FUN,X,A,B,Aeq,Beq,LB,UB,NONLCON,options,varargin)

/*fmincon可以在多元函数中找到最小值

FMINCON attempts to solve problems of the form:

min F(X) subject to: A*X <= B, Aeq*X = Beq (linear constraints)线性约束

X C(X) <= 0, Ceq(X) = 0 (nonlinear constraints)非线性约束

LB <= X <= UB (bounds)

*/

/*FMINCON implements four different algorithms: interior point, SQP,

% active set, and trust region reflective. Choose one via the option

% Algorithm: for instance, to choose SQP, set OPTIONS =

% optimoptions('fmincon','Algorithm','sqp'), and then pass OPTIONS to

% FMINCON.

fmincon函数应用四种不同的算法:内点法(interior point);序列二次规划算法(SQP);有效集法(active set);信赖域有效算法(trust region reflective)。

如果采用SQP算法可以设置 OPTIONS = optimoptions('fmincon','Algorithm','sqp'),再把OPTIONS赋给fmincon

*/

/*

% X = FMINCON(FUN,X0,A,B) starts at X0 and finds a minimum X to the

% function FUN, subject to the linear inequalities A*X <= B. FUN accepts

% input X and returns a scalar function value F evaluated at X. X0 may be

% a scalar, vector, or matrix.

%

% X = FMINCON(FUN,X0,A,B,Aeq,Beq) minimizes FUN subject to the linear

% equalities Aeq*X = Beq as well as A*X <= B. (Set A=[] and B=[] if no

% inequalities exist.)

%

% X = FMINCON(FUN,X0,A,B,Aeq,Beq,LB,UB) defines a set of lower and upper

% bounds on the design variables, X, so that a solution is found in

% the range LB <= X <= UB. Use empty matrices for LB and UB

% if no bounds exist. Set LB(i) = -Inf if X(i) is unbounded below;

% set UB(i) = Inf if X(i) is unbounded above.

%

% X = FMINCON(FUN,X0,A,B,Aeq,Beq,LB,UB,NONLCON) subjects the minimization

% to the constraints defined in NONLCON. The function NONLCON accepts X

% and returns the vectors C and Ceq, representing the nonlinear

% inequalities and equalities respectively. FMINCON minimizes FUN such

% that C(X) <= 0 and Ceq(X) = 0. (Set LB = [] and/or UB = [] if no bounds

% exist.)

%

% X = FMINCON(FUN,X0,A,B,Aeq,Beq,LB,UB,NONLCON,OPTIONS) minimizes with

% the default optimization parameters replaced by values in OPTIONS, an

% argument created with the OPTIMOPTIONS function. See OPTIMOPTIONS for

% details. For a list of options accepted by FMINCON refer to the

% documentation.

%

% X = FMINCON(PROBLEM) finds the minimum for PROBLEM. PROBLEM is a

% structure with the function FUN in PROBLEM.objective, the start point

% in PROBLEM.x0, the linear inequality constraints in PROBLEM.Aineq

% and PROBLEM.bineq, the linear equality constraints in PROBLEM.Aeq and

% PROBLEM.beq, the lower bounds in PROBLEM.lb, the upper bounds in

% PROBLEM.ub, the nonlinear constraint function in PROBLEM.nonlcon, the

% options structure in PROBLEM.options, and solver name 'fmincon' in

% PROBLEM.solver. Use this syntax to solve at the command line a problem

% exported from OPTIMTOOL. The structure PROBLEM must have all the fields.

%

% [X,FVAL] = FMINCON(FUN,X0,...) returns the value of the objective

% function FUN at the solution X.

%

% [X,FVAL,EXITFLAG] = FMINCON(FUN,X0,...) returns an EXITFLAG that

% describes the exit condition of FMINCON. Possible values of EXITFLAG

% and the corresponding exit conditions are listed below. See the

% documentation for a complete description.

% */

/*

% All algorithms:

% 1 First order optimality conditions satisfied.

% 0 Too many function evaluations or iterations.

% -1 Stopped by output/plot function.

% -2 No feasible point found.

% Trust-region-reflective, interior-point, and sqp:

% 2 Change in X too small.

% Trust-region-reflective:

% 3 Change in objective function too small.

% Active-set only:

% 4 Computed search direction too small.

% 5 Predicted change in objective function too small.

% Interior-point and sqp:

% -3 Problem seems unbounded.

所有算法中EXITFLAG返回值涵义

1 满足一阶最优性条件

0函数计算或迭代太多。无法求解

-1 被输出和绘图功能阻止

-2找不到可行点

Trust-region-reflective, interior-point, and sqp:三种算法才有的返回值

2 X变化太小

Active-set 算法才有的返回值

4计算搜索的方向太小

5目标函数的预测变化太小。

Interior-point and sqp才有的

-3 问题没有边界

*/

/*

% [X,FVAL,EXITFLAG,OUTPUT] = FMINCON(FUN,X0,...) returns a structure

% OUTPUT with information such as total number of iterations, and final

% objective function value. See the documentation for a complete list.

返回包含迭代总数和最终目标函数值等信息的结构输出

*/

/*

% [X,FVAL,EXITFLAG,OUTPUT,LAMBDA] = FMINCON(FUN,X0,...) returns the

% Lagrange multipliers at the solution X: LAMBDA.lower for LB,

% LAMBDA.upper for UB, LAMBDA.ineqlin is for the linear inequalities,

% LAMBDA.eqlin is for the linear equalities, LAMBDA.ineqnonlin is for the

% nonlinear inequalities, and LAMBDA.eqnonlin is for the nonlinear

% equalities.

返回解x处的拉格朗日乘数:lambda.lower表示lb,lambda.upper表示ub,

lambda.ineqlin表示线性不等式,lambda.eqlin表示线性等式,

lambda.ineqnonlin表示非线性不等式,lambda.eqnonlin表示非线性不等式。

*/

/*

% [X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD] = FMINCON(FUN,X0,...) returns the

% value of the gradient of FUN at the solution X.

返回解决方案x的fun渐变值。

%*/

/* [X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = FMINCON(FUN,X0,...)

% returns the value of the exact or approximate Hessian of the Lagrangian

% at X.

返回X的朗格朗日精确解或者近似Hessian矩阵

*/

/* Examples

% FUN can be specified using @:

% X = fmincon(@humps,...)

% In this case, F = humps(X) returns the scalar function value F of

% the HUMPS function evaluated at X.

%

% FUN can also be an anonymous function:

% X = fmincon(@(x) 3*sin(x(1))+exp(x(2)),[1;1],[],[],[],[],[0 0])

% returns X = [0;0].

%

% If FUN or NONLCON are parameterized, you can use anonymous functions to

% capture the problem-dependent parameters. Suppose you want to minimize

% the objective given in the function myfun, subject to the nonlinear

% constraint mycon, where these two functions are parameterized by their

% second argument a1 and a2, respectively. Here myfun and mycon are

% MATLAB file functions such as

%

% function f = myfun(x,a1)

% f = x(1)^2 + a1*x(2)^2;

%

% function [c,ceq] = mycon(x,a2)

% c = a2/x(1) - x(2);

% ceq = [];

%

% To optimize fo

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值