fmincon Constraint Query Optimization

1 view (last 30 days)
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.

Accepted Answer

Matt J
Matt J on 18 Nov 2020
Edited: Matt J on 18 Nov 2020
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 Comments
Matt J
Matt J on 18 Nov 2020
Edited: Matt J on 18 Nov 2020
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!