# infeasibility

Constraint violation at a point

## Description

Use `infeasibility`

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

**Tip**

For the full workflow, see Problem-Based Optimization Workflow or Problem-Based Workflow for Solving Equations.

## Examples

### 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)

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.

### Compute Multiple Constraint Violations

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*
0
2
0

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

## Input Arguments

`constr`

— Optimization constraint

`OptimizationEquality`

object | `OptimizationInequality`

object | `OptimizationConstraint`

object

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.

`pt`

— Point to evaluate

structure with field names that match the optimization variable
names

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

`infeas`

— Infeasibility of constraint

real array

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.

**Warning**

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**

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)