请问matlab中 fmincon()的用法?

 我来答
whdbsa
2011-01-21 · TA获得超过828个赞
知道小有建树答主
回答量:687
采纳率:0%
帮助的人:527万
展开全部
你的代码中调用fmincon函数中@total1不应该是@myfun目标函数吗,后面的那个@total1应该是@mycon为非线性约束
function f = myfun(x)
f = 0.192457*1e-4*(x(2)+2)*x(1)^2*x(3);

function [c,ceq] = mycon(x)
c(1)=350-163*x^(-2.86)*x(3)^0.86;
c(2)=10-0.4*0.01^x(1)^(-4)*x(2)*x(3)^3;
c(3)=(x(2)+1.5)*x(1)+0.44*0.01*x(1)^(-4)*x(2)*x(3)^3-3.7*x(3);
c(4)=375-356000*x(1)^(-4)*x(2)*x(3)^3;
c(5)=4-x(3)/x(1);

A=[-1 0 0;1 0 0;0 -1 0;0 1 0;0 0 -1; 0 0 1];
b=[-1;4;-4.5;50;-10;30];
x0= [2.0;5.0;25.0];
lb=zeros(3,1);
[x,fval,exitflag,output,lambda]=fmincon(@myfun,x0,A,b,[],[],lb,[],@mycon)
这样才对!
chaocow1123
2011-01-20
知道答主
回答量:8
采纳率:0%
帮助的人:0
展开全部
FMINCON finds a constrained minimum of a function of several variables.
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)

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 the structure
OPTIONS, an argument created with the OPTIMSET function. See OPTIMSET
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.

All algorithms:
1 First order optimality conditions satisfied to the specified
tolerance.
0 Maximum number of function evaluations or iterations reached.
-1 Optimization terminated by the output function.
-2 No feasible point found.
Trust-region-reflective and interior-point:
2 Change in X less than the specified tolerance.
Trust-region-reflective:
3 Change in the objective function value less than the specified
tolerance.
Active-set only:
4 Magnitude of search direction smaller than the specified tolerance
and constraint violation less than options.TolCon.
5 Magnitude of directional derivative less than the specified
tolerance and constraint violation less than options.TolCon.
Interior-point:
-3 Problem appears to be unbounded.

[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,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD] = FMINCON(FUN,X0,...) returns the
value of the gradient of FUN at the solution X.

[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] = FMINCON(FUN,X0,...)
returns the value of the exact or approximate Hessian of the Lagrangian
at X.

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
M-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 for specific values of a1 and a2, first assign the values
to these two parameters. Then create two one-argument anonymous
functions that capture the values of a1 and a2, and call myfun and
mycon with two arguments. Finally, pass these anonymous functions to
FMINCON:

a1 = 2; a2 = 1.5; % define parameters first
options = optimset('Algorithm','active-set'); % run active-set algorithm
x = fmincon(@(x) myfun(x,a1),[1;2],[],[],[],[],[],[],@(x) mycon(x,a2),options)

See also optimset, optimtool, fminunc, fminbnd, fminsearch, @, function_handle.

Reference page in Help browser
doc fmincon
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式