Main Content


Constraint violation at a point


Use infeasibility to find the numeric value of a constraint violation at a point.


infeas = infeasibility(constr,pt) returns the amount of violation of the constraint constr at the point pt.


collapse all

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)
infeas = 2

The point is not feasible with respect to this constraint.

Check the feasibility with respect to the other constraint.

infeas = infeasibility(cons2,pt)
infeas = 0

The point is feasible with respect to this constraint.

Check whether a point satisfies a constraint that has multiple conditions.

Set up an optimization variable and a vector of constraints.

x = optimvar('x',3,2);
cons = sum(x,2) <= [1;3;2];

Check whether the point pt.x = [1,-1;2,3;3,-1] satisfies these constraints.

pt.x = [1,-1;2,3;3,-1];
infeas = infeasibility(cons,pt)
infeas = 3×1


The point is not feasible with respect to the second constraint.

Input Arguments

collapse all

Optimization constraint, specified as an OptimizationEquality object, OptimizationInequality object, or OptimizationConstraint object. constr can represent a single constraint or an array of constraints.

Example: constr = x + y <= 1 is a single constraint when x and y are scalar variables.

Example: constr = sum(x) == 1 is an array of constraints when x is an array of two or more dimensions.

Point to evaluate, specified as a structure with field names that match the optimization variable names, for optimization variables in the constraint. The size of each field in pt must match the size of the corresponding optimization variable.

Example: pt.x = 5*eye(3)

Data Types: struct

Output Arguments

collapse all

Infeasibility of constraint, returned as a real array. Each zero entry represents a feasible constraint, and each positive entry represents an infeasible constraint. The size of infeas is the same as the size of the constraint constr. For an example of nonscalar infeas, see Compute Multiple Constraint Violations.


The problem-based approach does not support complex values in the following: an objective function, nonlinear equalities, and nonlinear inequalities. If a function calculation has a complex value, even as an intermediate value, the final result might be incorrect.

Version History

Introduced in R2017b