# getconstraint

Obtain mixed input/output constraints from model predictive controller

## Description

## Examples

### Retrieve Custom Constraints from MPC Controller

Create a third-order plant model with two manipulated variables, one measured disturbance, and two measured outputs.

plant = rss(3,2,3); plant.D = 0; plant = setmpcsignals(plant,'mv',[1 2],'md',3);

Create an MPC controller for this plant.

MPCobj = mpc(plant,0.1);

-->The "PredictionHorizon" property is empty. Assuming default 10. -->The "ControlHorizon" property is empty. Assuming default 2. -->The "Weights.ManipulatedVariables" property is empty. Assuming default 0.00000. -->The "Weights.ManipulatedVariablesRate" property is empty. Assuming default 0.10000. -->The "Weights.OutputVariables" property is empty. Assuming default 1.00000.

Assume that you have two soft constraints.

$$\begin{array}{l}{u}_{1}+{u}_{2}\le 5\\ {y}_{2}+v\le 10\end{array}$$

Set the constraints for the MPC controller.

E = [1 1; 0 0]; F = [0 0; 0 1]; G = [5;10]; V = [1;1]; S = [0;1]; setconstraint(MPCobj,E,F,G,V,S)

Retrieve the constraints from the controller.

[E,F,G,V,S] = getconstraint(MPCobj)

`E = `*2×2*
1 1
0 0

`F = `*2×2*
0 0
0 1

`G = `*2×1*
5
10

`V = `*2×1*
1
1

`S = `*2×1*
0
1

## Input Arguments

`MPCobj`

— Model predictive controller

MPC controller object

Model predictive controller, specified as an MPC controller
object. To create an MPC controller, use `mpc`

.

## Output Arguments

`E`

— Manipulated variable constraint constant

*N*_{c}-by-*N*_{mv}
array | `[]`

_{c}

_{mv}

Manipulated variable constraint constant, returned as an
*N _{c}*-by-

*N*array, where

_{mv}*N*is the number of constraints, and

_{c}*N*is the number of manipulated variables.

_{mv}If `MPCobj`

has no mixed input/output constraints, then
`E`

is `[]`

.

`F`

— Controlled output constraint constant

*N*_{c}-by-*N*_{y}
array | `[]`

_{c}

_{y}

Controlled output constraint constant, returned as an
*N _{c}*-by-

*N*array, where

_{y}*N*is the number of controlled outputs (measured and unmeasured).

_{y}If `MPCobj`

has no mixed input/output constraints, then
`F`

is `[]`

.

`G`

— Mixed input/output constraint constant

column vector of length
*N*_{c} | `[]`

_{c}

Mixed input/output constraint constant, returned as a column vector of
length *N _{c}*., where

*N*is the number of constraints.

_{c}If `MPCobj`

has no mixed input/output constraints, then
`G`

is `[]`

.

`V`

— Constraint softening constant

column vector of length
*N*_{c} | `[]`

_{c}

Constraint softening constant representing the equal concern for the relaxation (ECR),
returned as a column vector of length
*N _{c}*, where

*N*is the number of constraints. If

_{c}`MPCobj`

has no mixed input/output
constraints, then `V`

is `[]`

.If `V`

is not specified, a default value
of `1`

is applied to all constraint inequalities
and all constraints are soft. This behavior is the same as the default
behavior for output bounds, as described in Standard Cost Function.

To make the *i*^{th} constraint
hard, specify *V*(*i*)
= 0.

To make the *i*^{th} constraint
soft, specify *V*(*i*)
> 0 in keeping with the constraint violation
magnitude you can tolerate. The magnitude violation depends on the
numerical scale of the variables involved in the constraint.

In general, as *V*(*i*) decreases,
the controller hardens the constraints by decreasing the constraint
violation that is allowed.

`S`

— Measured disturbance constraint constant

*N*_{c}-by-*N*_{v}
array | `[]`

_{c}

_{v}

Measured disturbance constraint constant, returned as an
*N _{c}*-by-

*N*array, where

_{v}*N*is the number of measured disturbances.

_{v}If there are no measured disturbances in the mixed input/output constraints, or
`MPCobj`

has no mixed input/output constraints, then
`S`

is `[]`

.

## Algorithms

### Mixed Input/Output Constraints

The general form of the mixed input/output constraints is:

*E**u*(*k* +
*j*) +
*F**y*(*k* +
*j*) + *S**v*(*k* +
*j*) ≤ *G* +
*ε**V*

Here, *j* = 0,...,*p*, and:

*p*is the prediction horizon.*k*is the current time index.*u*is a column vector manipulated variables.*y*is a column vector of all plant output variables.*v*is a column vector of measured disturbance variables.*ε*is a scalar slack variable used for constraint softening (as in Standard Cost Function).*E*,*F*,*G*,*V*, and*S*are constant matrices.

Since the MPC controller does not optimize
*u*(*k*+*p*),
`getconstraint`

calculates the last constraint at time

assuming that *k*+*p**u*(*k*+*p*) =
*u*(*k*+*p*-1).

## Version History

**Introduced in R2011a**

## Open Example

You have a modified version of this example. Do you want to open this example with your edits?

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