필터 지우기
필터 지우기

fmincon Constraint Query Optimization

조회 수: 2 (최근 30일)
Harshvardhan Tandon
Harshvardhan Tandon 2020년 11월 18일
댓글: Harshvardhan Tandon 2020년 11월 19일
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.
Harshvardhan Tandon
Harshvardhan Tandon 2020년 11월 19일
Understood.

댓글을 달려면 로그인하십시오.

추가 답변 (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