%% Compute Constraint Violation
% Check whether a point satisfies a constraint.
% Set up optimization variables and two constraints.

x = optimvar('x');
y = optimvar('y');
cons = x + y <= 2;
cons2 = x + y/4 <= 1;

% Check whether the point x = 0, y = 4 satisfies the constraint named cons. A point is feasible when its infeasibility is zero.

pt.x = 0;
pt.y = 4;
infeas = infeasibility(cons,pt)

% The point is not feasible with respect to this constraint.
% Check the feasibility with respect to the other constraint.

infeas = infeasibility(cons2,pt)

% The point is feasible with respect to this constraint.
% Copyright 2012-2021 The MathWorks, Inc.