fmincon Constraint Query Optimization

2 次查看(过去 30 天)
Is it possible to split up Aeq and beq (equality constraints) (or any any other constraint A,b, nonlcon, c(x),ceq(x)) for the input variables i am entering into my function ?
If i have 10 variables to optimize, for eg. x1,x2,.......x10. Can i make A1*(x1,x2,x3,x4,x5) = b1 and A2*(x6,x7,x8,x9,x10) = b2. If this is possible how do i show this in matlab ?(can it be done for the other optimizing variables)
Fmincon works on the syntax above.

采纳的回答

Matt J
Matt J 2020-11-18
编辑:Matt J 2020-11-18
Generally, all constraints must operate on the total set of unknows x1,..x10. However, given A1,A2, b1,b2 it is simple enough to obtain the combined constraint matrices using blkdiag,
Aeq=blkdiag(A1,A2);
beq=[b1;b2]
The one exception is if you are working in the problem-based framework, in which case you can do things like
x=optimvar('x',10,1);
prob=optimproblem;
prob.Constraints.con1=A1*x(1:5)<=b1;
prob.Constraints.con2=A2*x(6:10)<=b2;
  3 个评论
Matt J
Matt J 2020-11-18
编辑:Matt J 2020-11-18
The nonlcon function must be written to accept a vector containing all 10 unknowns as input, but within that function you can use that vector or parts of it in any way you wish, just as long as the constraint functions you implement are differentiable. So, for example, the following is legitimate,
function [c,ceq]=nonlcon(x)
c=[];
ceq(1)=sum(x(1:5))-10;
ceq(2)=sum(x(6:10))+25;
end
Bear in mind, however, that because the constraints in this example are linear, the solver will not process them optimally if they are put in the nonlcon function in this fashion. They should really be part of your linear constraint matrices A,b,Aeq,beq.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by