# setterminal

Terminal weights and constraints

## Description

## Examples

### Specify Constraints and Penalty Weights at Last Prediction Horizon Step

Create an MPC controller for a plant with three output variables and two manipulated variables.

plant = rss(3,3,2); plant.D = 0; 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. for output(s) y1 y2 and zero weight for output(s) y3

Specify a prediction horizon of `8`

.

mpcobj.PredictionHorizon = 8;

Define the following penalty weights and constraints:

Diagonal penalty weights of

`1`

and`10`

on the first two output variablesLower bounds of

`0`

and`-1`

on the first and third outputs respectivelyUpper bound of

`2`

on the second outputLower bound of

`1`

on the first manipulated variable

Y = struct('Weight',[1,10,0],'Min',[0,-Inf,-1],'Max',[Inf,2,Inf]); U = struct('Min',[1,-Inf]);

Specify the constraints and penalty weights at the last step of the prediction horizon.

setterminal(mpcobj,Y,U)

### Specify Terminal Constraints For Final Prediction Horizon Range

Create an MPC controller for a plant with three output variables and two manipulated variables.

plant = rss(3,3,2); plant.D = 0; 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. for output(s) y1 y2 and zero weight for output(s) y3

Specify a prediction horizon of `10`

.

mpcobj.PredictionHorizon = 10;

Define the following terminal constraints:

Lower bounds of

`0`

and`-1`

on the first and third outputs respectivelyUpper bound of

`2`

on the second outputLower bound of

`1`

on the first manipulated variable

Y = struct('Min',[0,-Inf,-1],'Max',[Inf,2,Inf]); U = struct('Min',[1,-Inf]);

Specify the constraints beginning at step `5`

and ending at the last step of the prediction horizon.

setterminal(mpcobj,Y,U,5)

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

.

`Y`

— Terminal weights and constraints for the output variables

structure

Terminal weights and constraints for the output variables, specified as a structure with the following fields:

`Weight` | 1-by-n vector of nonnegative
weights_{y} |

`Min` | 1-by-n vector of lower
bounds_{y} |

`Max` | 1-by-n vector of upper
bounds_{y} |

`MinECR` | 1-by-n vector of
constraint-softening Equal Concern for the Relaxation (ECR) values for the lower
bounds_{y} |

`MaxECR` | 1-by-n vector of
constraint-softening ECR values for the upper bounds_{y} |

*n _{y}* is the number of controlled outputs of
the MPC controller.

If the `Weight`

, `Min`

or `Max`

field is empty, the values in `MPCobj`

are used at all prediction
horizon steps including the last. For the standard bounds, if any element of the
`Min`

or `Max`

field is infinite, the corresponding
variable is unconstrained at the terminal step.

Off-diagonal weights are zero (as described in Standard Cost Function). To apply nonzero off-diagonal terminal weights, you must augment the plant model. See Provide LQR Performance Using Terminal Penalty Weights.

By default, `Y.MinECR`

= `Y.MaxECR`

= 1 (soft
output constraints).

Choose the `ECR`

magnitudes carefully, accounting for the
importance of each constraint and the numerical magnitude of a typical violation.

`U`

— Terminal weights and constraints for the manipulated variables

structure

Terminal weights and constraints for the manipulated variables, specified as a structure with the following fields:

`Weight` | 1-by-n vector of nonnegative
weights_{u} |

`Min` | 1-by-n vector of lower
bounds_{u} |

`Max` | 1-by-n vector of upper
bounds_{u} |

`MinECR` | 1-by-n vector of
constraint-softening Equal Concern for the Relaxation (ECR) values for the lower
bounds_{u} |

`MaxECR` | 1-by-n vector of
constraint-softening ECR values for the upper bounds_{u} |

*n _{u}* is the number of manipulated variables
of the MPC controller.

If the `Weight`

, `Min`

or `Max`

field is empty, the values in `MPCobj`

are used at all prediction
horizon steps including the last. For the standard bounds, if individual elements of the
`Min`

or `Max`

fields are infinite, the
corresponding variable is unconstrained at the terminal step.

Off-diagonal weights are zero (as described in Standard Cost Function). To apply nonzero off-diagonal terminal weights, you must augment the plant model. See Provide LQR Performance Using Terminal Penalty Weights.

By default, `U.MinECR`

= `U.MaxECR`

= 0 (hard
manipulated variable constraints)

Choose the ECR magnitudes carefully, accounting for the importance of each constraint and the numerical magnitude of a typical violation.

`Pt`

— Initial application step for terminal weight and constraints

prediction horizon *p* (default) | integer less than *p*

Step in the prediction horizon, specified as an integer between 1 and
*p*, where *p* is the prediction horizon. The
terminal weights and constraints are applied from prediction step `Pt`

to the end.

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