Create Constraint Array
Create a 4-by-6 optimization variable matrix named x.
x = optimvar('x',4,6);
Create the constraints that each row of x sums to one.
constrsum = sum(x,2) == 1
constrsum = 4×1 OptimizationConstraint array with properties: IndexNames: {{} {}} See constraint formulation with showconstr.
View the constraints.
showconstr(constrsum)
(1, 1) x(1, 1) + x(1, 2) + x(1, 3) + x(1, 4) + x(1, 5) + x(1, 6) == 1 (2, 1) x(2, 1) + x(2, 2) + x(2, 3) + x(2, 4) + x(2, 5) + x(2, 6) == 1 (3, 1) x(3, 1) + x(3, 2) + x(3, 3) + x(3, 4) + x(3, 5) + x(3, 6) == 1 (4, 1) x(4, 1) + x(4, 2) + x(4, 3) + x(4, 4) + x(4, 5) + x(4, 6) == 1
To include the constraints in an optimization problem, use dot notation.
prob = optimproblem; prob.Constraints.constrsum = constrsum;