Main Content

本页对应的英文页面已更新,但尚未翻译。 若要查看最新内容,请点击此处访问英文页面。

infeasibility

Constraint violation at a point

说明

示例

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

示例

全部折叠

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 = 3 satisfies the constraint named cons. A point is feasible when its infeasibility is zero.

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

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

     0
     2
     0

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

输入参数

全部折叠

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

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

示例: 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.

示例: pt.x = 5*eye(3)

数据类型: struct

Output Arguments

全部折叠

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 an objective function, nonlinear equalities, or nonlinear inequalities. If a function calculation has a complex value, even as an intermediate value, the final result can be incorrect.

在 R2017b 中推出