MATLAB: Fmincon Constraint Query Optimization

fminconMATLABoptimizationOptimization Toolboxsyntax

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.

Best Answer

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;