[英]MATLAB - Solving a multivariable constraint optimization
我有一个由三个未知数组成的系统,比方说x
, y
, z
。 我想解决以下非线性系统:
f1(x,y,z) = 0
f2(x,y,z) = 0
由于我有3个未知数但2个等式,因此我想说出z
最大化的结果。
并且存在三个约束:
x > 0
y > 0
z > 0
我怎么解决这个问题? 总结一下:
编辑
到目前为止,这是我使用fmincon
所做的事情:
% objective function
% Want to minimize the function 1/z (so maximize the variable)
function f = objFun(arg)
x = arg(1);
y = arg(2);
z = arg(3);
f = 1/z;
end
% My two nonlinear equalities f1, f2
function [c, ceq] = NLPart(arg, someInput)
% dont want to get into the detail of the equation since it is
% very long, but at the end:
x = arg(1);
y = arg(2);
z = arg(3);
c = 0;
% The equations below are dummy. they are just some nonlinear combination of the three
ceq(1) = x*y*z;
ceq(2) = x/y + z^2;
end
然后在MATLAB中,运行以下命令:
system = @ (arg) NLPart(arg, [1 2 3]);
obj = @ (arg) objFun(arg);
fmincon(obj, init_state, [], [], [], [], [0 0 0], [], system);
这给了我以下错误:
使用svd时出错SVD的输入不得包含NaN或Inf。
pinv中的错误(第29行)[U,S,V] = svd(A,0);
qpsub(第463行)中的错误projSD = pinv(projH)*(-Zgf);
nlconst(第618行)错误[SD,lambda,exitflagqp,outputqp,howqp,ACTIND] ...
fmincon中的错误(第794行)[X,FVAL,LAMBDA,EXITFLAG,OUTPUT,GRAD,HESSIAN] = ...
顺便说一句,我的目标1/z
,我希望它等于零(通过最大化z
)。 我不知道我写的正确吗
您基本上想做一个优化,其中目标函数的定义如下:
h(x,y,z) = z;
具有以下非线性等式约束:
f1(x,y,z) = 0;
f2(x,y,z) = 0;
以及以下下界:
x > 0, y > 0, z > 0
是的,您可以在MATLAB中执行此操作。 您应该能够在以下语法中使用“ fmincon”:
x = fmincon(fun,x0,[],[],[],[],lb,[],nonlcon)
x0是一个三元素向量,结果也将采用相同的格式,这将为您提供x,y和z的值。 请查看fmincon的文档以了解更多详细信息: http : //www.mathworks.com/help/optim/ug/fmincon.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.