## Linear Constraints

### What Are Linear Constraints?

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 `fmincon`, `intlinprog`, `linprog`, `lsqlin`, `quadprog`, multiobjective solvers, and some Global Optimization Toolbox solvers.

### Linear Inequality Constraints

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 `A` and `b` arguments.

For example, suppose that you have the following linear inequalities as constraints:

x1 + x3 ≤ 4,
2x2x3 ≥ –2,
x1x2 + x3x4 ≥ 9.

Here, m = 3 and n = 4.

Write these constraints using the following matrix A and vector b:

`$\begin{array}{l}A=\left[\begin{array}{cccc}1& 0& 1& 0\\ 0& -2& 1& 0\\ -1& 1& -1& 1\end{array}\right],\\ b=\left[\begin{array}{c}4\\ 2\\ -9\end{array}\right].\end{array}$`

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 Matrix Arguments.

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 Equality 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 `Aeq` and `beq` arguments in the same way as described for the `A` and `b` arguments in Linear Inequality Constraints.

Watch now