Several optimization solvers accept linear constraints, which are restrictions on
the solution x to satisfy linear equalities or inequalities.
Solvers that accept linear constraints include
quadprog, multiobjective solvers, and some Global Optimization Toolbox solvers.
Linear inequality constraints have the form A·x ≤ b. When A is m-by-n, there are m constraints on a variable x with n components. You supply the m-by-n matrix A and the m-component vector b.
Pass linear inequality constraints in the
For example, suppose that you have the following linear inequalities as constraints:
x1 + x3 ≤
2x2 – x3 ≥ –2,
x1 – x2 + x3 – x4 ≥ 9.
Here, m = 3 and n = 4.
Write these constraints using the following matrix A and vector b:
Notice that the “greater than” inequalities are first multiplied by –1 to put them in “less than” inequality form. In MATLAB® syntax:
A = [1 0 1 0; 0 -2 1 0; -1 1 -1 1]; b = [4;2;-9];
You do not need to give gradients for linear constraints; solvers calculate them automatically. Linear constraints do not affect Hessians.
Even if you pass an initial point
x0 as a matrix, solvers pass
the current point x as a column vector to linear constraints. See
For a more complex example of linear constraints, see Set Up a Linear Program, Solver-Based.
Intermediate iterations can violate linear constraints. See Iterations Can Violate Constraints.
Linear equalities have the form Aeq·x = beq, which represents m equations with n-component vector x. You supply the m-by-n matrix Aeq and the m-component vector beq.
Pass linear equality constraints in the
beq arguments in the same way as described for the
b arguments in Linear Inequality Constraints.