%% Create Inequalities in Loop
% Create the constraint that a two-element variable x must lie in the intersections of a number of disks whose centers and radii are in the arrays centers and radii.

x = optimvar('x',1,2);
centers = [1 -2;3 -4;-2 3];
radii = [6 7 8];
constr = optimineq(length(radii));
for i = 1:length(constr)
    constr(i) = sum((x - centers(i,:)).^2) <= radii(i)^2;
end

% View the inequality expressions.

show(constr)

%
% Instead of using a loop, you can create the same constraints by using matrix operations on the variables.

constr2 = sum(([x;x;x] - centers).^2,2) <= radii'.^2;

% Creating inequalities in a loop can be more time consuming than creating inequalities by using matrix operations.
% Copyright 2019 The MathWorks, Inc.