# mpcmoveAdaptive

Compute optimal control with prediction model updating

## Syntax

## Description

computes the optimal manipulated variable moves at the current time. This result depends on the
properties contained in the MPC controller, the controller states, an updated prediction model,
and the nominal values. The result also depends on the measured output variables, the output
references (setpoints), and the measured disturbance inputs.
`mv`

= mpcmoveAdaptive(`MPCobj`

,`x`

,`Plant`

,`Nominal`

,`ym`

,`r`

,`v`

)`mpcmoveAdaptive`

updates the controller state, `x`

, when
using default state estimation. Call `mpcmoveAdaptive`

repeatedly to simulate
closed-loop model predictive control.

`[`

returns additional details about the solution in a structure. To view the predicted optimal
trajectory for the entire prediction horizon, plot the sequences provided in
`mv`

,`info`

]
= mpcmoveAdaptive(`MPCobj`

,`x`

,`Plant`

,`Nominal`

,`ym`

,`r`

,`v`

)`info`

. To determine whether the optimal control calculation completed
normally, check `info.Iterations`

and `info.QPCode`

.

`[___] = mpcmoveAdaptive(___,`

alters selected controller settings using options you specify with `options`

)`mpcmoveopt`

. These changes apply for the current time instant only, enabling a
command-line simulation using `mpcmoveAdaptive`

to mimic the Adaptive
MPC Controller block in Simulink^{®} in a computationally efficient manner.

## Input Arguments

`MPCobj`

— MPC controller

MPC controller object

MPC controller, specified as an implicit MPC controller object.
To create the MPC controller, use the `mpc`

command.

`x`

— Current MPC controller state

`mpcstate`

object

Current MPC controller state, specified as an `mpcstate`

object.

Before you begin a simulation with `mpcmoveAdaptive`

,
initialize the controller state using `x = mpcstate(MPCobj)`

.
Then, modify the default properties of `x`

as appropriate.

If you are using default state estimation, `mpcmoveAdaptive`

expects `x`

to
represent `x[n|n-1]`

. The `mpcmoveAdaptive`

command
updates the state values in the previous control interval with that
information. Therefore, you should not programmatically update `x`

at
all. The default state estimator employs a linear time-varying Kalman
filter.

If you are using custom state estimation, `mpcmoveAdaptive`

expects `x`

to
represent `x[n|n]`

. Therefore, prior to each `mpcmoveAdaptive`

command,
you must set `x.Plant`

, `x.Disturbance`

,
and `x.Noise`

to the best estimates of these states
(using the latest measurements) at the current control interval.

For more information on state estimation for adaptive MPC and time-varying MPC, see State Estimation.

`Plant`

— Updated prediction model

discrete-time state-space model | model array

Updated prediction model, specified as one of the following:

A delay-free, discrete-time state-space (

`ss`

) model. This plant is the update to`MPCobj.Model.Plant`

and it must:Have the same sample time as the controller; that is,

`Plant.Ts`

must match`MPCobj.Ts`

Have the same input and output signal configurations, such as type, order, and dimensions

Define the same states as the controller prediction model,

`MPCobj.Model.Plant`

An array of up to

*p*+1 delay-free, discrete-time state-space models, where*p*is the prediction horizon of`MPCobj`

. Use this option to vary the controller prediction model over the prediction horizon.If

`Plant`

contains fewer than*p*+1 models, the last model repeats for the rest of the prediction horizon.

**Tip**

If you use a plant other than a delay-free, discrete-time state-space
model to define the prediction model in `MPCobj`

,
you can convert it to such a model to determine the prediction model
structure.

If the original plant is | Then |
---|---|

Not a state-space model | Convert it to a state-space model using `ss` . |

A continuous-time model | Convert it to a discrete-time model with the same sample time
as the controller, `MPCobj.Ts` , using `c2d` with default forward Euler discretization. |

A model with delays | Convert the delays to states using `absorbDelay` . |

`Nominal`

— Updated nominal conditions

structure | structure array | `[]`

Updated nominal conditions, specified as one of the following:

A structure of with the following fields:

Field

Description

Default

`X`

Plant state at operating point

`[]`

`U`

Plant input at operating point, including manipulated variables and measured and unmeasured disturbances

`[]`

`Y`

Plant output at operating point

`[]`

`DX`

For continuous-time models,

`DX`

is the state derivative at operating point:`DX`

=*f*(`X`

,`U`

). For discrete-time models,`DX`

=*x*(*k*+1)-*x*(*k*)=*f*(`X`

,`U`

)-`X`

.`[]`

An array of up to

*p*+1 nominal condition structures, where*p*is the prediction horizon of`MPCobj`

. Use this option to vary controller nominal conditions over the prediction horizon.If

`Nominal`

contains fewer than*p*+1 structures, the last structure repeats for the rest of the prediction horizon.

If `Nominal`

is empty, `[]`

,
or if a field is missing or empty, `mpcmoveAdaptive`

uses
the corresponding `MPCobj.Model.Nominal`

value.

`ym`

— Current measured outputs

row vector of length *N*_{ym}

_{ym}

Current measured outputs, specified as a row vector of length
*N _{ym}* vector, where

*N*is the number of measured outputs.

_{ym}If you are using custom state estimation, `ym`

is
ignored. If you set `ym`

= `[]`

,
then `mpcmoveAdaptive`

uses the appropriate nominal
value.

`r`

— Plant output reference values

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

_{y}

Plant output reference values, specified as a
*p*-by-*N _{y}* array, where

*p*is the prediction horizon of

`MPCobj`

and
*N*is the number of outputs. Row

_{y}`r(i,:)`

defines the reference values at step *i*of the prediction horizon.

`r`

must contain at least one row. If `r`

contains fewer
than *p* rows, `mpcmoveAdaptive`

duplicates the last row
to fill the *p*-by-*N _{y}* array. If you
supply exactly one row, therefore, a constant reference applies for the entire prediction
horizon.

If you set `r`

= `[]`

, then `mpcmoveAdaptive`

uses
the appropriate nominal value.

To implement reference previewing, which can improve tracking
when a reference varies in a predictable manner, `r`

must
contain the anticipated variations, ideally for *p* steps.

`v`

— Current and anticipated measured disturbances

*p*-by-*N*_{md} array | `[]`

_{md}

Current and anticipated measured disturbances, specified as a
*p*-by-*N _{md}* array, where

*p*is the prediction horizon of

`MPCobj`

and
*N*is the number of measured disturbances. Row

_{md}`v(i,:)`

defines the expected measured disturbance values at step
*i*of the prediction horizon.

Modeling of measured disturbances provides feedforward control
action. If your plant model does not include measured disturbances,
use `v`

= `[]`

.

`v`

must contain at least one row. If `v`

contains fewer
than *p* rows, `mpcmoveAdaptive`

duplicates the last row
to fill the *p*-by-*N _{md}* array. If
you supply exactly one row, therefore, a constant measured disturbance applies for the entire
prediction horizon.

If you set `v`

= `[]`

, then `mpcmoveAdaptive`

uses
the appropriate nominal value.

To implement disturbance previewing, which can improve tracking
when a disturbance varies in a predictable manner, `v`

must
contain the anticipated variations, ideally for *p* steps.

`options`

— Override values for selected controller properties

`mpcmoveopt`

object

Override values for selected properties of `MPCobj`

, specified as an
options object you create with `mpcmoveopt`

. These options apply to the current
`mpcmoveAdaptive`

time instant only. Using `options`

yields the same result as redefining or modifying `MPCobj`

before each call
to `mpcmoveAdaptive`

, but involves considerably less overhead. Using
`options`

is equivalent to using an Adaptive MPC Controller
Simulink block in combination with optional input signals that modify controller
settings, such as MV and OV constraints.

## Output Arguments

`mv`

— Optimal manipulated variable moves

column vector

Optimal manipulated variable moves, returned as a column vector of length
*N _{mv}*, where

*N*is the number of manipulated variables.

_{mv}If the controller detects an infeasible optimization problem or encounters numerical
difficulties in solving an ill-conditioned optimization problem, `mv`

remains at its most recent successful solution, `xc.LastMove`

.

Otherwise, if the optimization problem is feasible and the solver reaches the
specified maximum number of iterations without finding an optimal solution,
`mv`

:

Remains at its most recent successful solution if the

`Optimizer.UseSuboptimalSolution`

property of the controller is`false`

.Is the suboptimal solution reached after the final iteration if the

`Optimizer.UseSuboptimalSolution`

property of the controller is`true`

. For more information, see Suboptimal QP Solution.

`info`

— Solution details

structure

Solution details, returned as a structure with the following fields.

`Uopt`

— Optimal manipulated variable sequence

(*p*+1)-by-*N*_{mv}
array

_{mv}

Predicted optimal manipulated variable adjustments (moves), returned as a
(*p*+1)-by-*N _{mv}*
array, where

*p*is the prediction horizon and

*N*is the number of manipulated variables.

_{mv}`Uopt(i,:)`

contains the calculated optimal values at
time `k+i-1`

, for `i = 1,...,p`

, where
`k`

is the current time. The first row of
`Info.Uopt`

contains the same manipulated variable
values as output argument `mv`

. Since the controller does
not calculate optimal control moves at time `k+p`

,
`Uopt(p+1,:)`

is equal to
`Uopt(p,:)`

.

`Yopt`

— Optimal output variable sequence

(*p*+1)-by-*N*_{y}
array

_{y}

Optimal output variable sequence, returned as a
(*p*+1)-by-*N _{y}*
array, where

*p*is the prediction horizon and

*N*is the number of outputs.

_{y}The first row of `Info.Yopt`

contains the calculated
outputs at time `k`

based on the estimated states and
measured disturbances; it is not the measured output at time
`k`

. `Yopt(i,:)`

contains the
predicted output values at time `k+i-1`

, for ```
i =
1,...,p+1
```

.

`Yopt(i,:)`

contains the calculated output values at time
`k+i-1`

, for `i = 2,...,p+1`

, where
`k`

is the current time. `Yopt(1,:)`

is computed based on the estimated states and measured disturbances.

`Xopt`

— Optimal prediction model state sequence

(*p*+1)-by-*N*_{x}
array

_{x}

Optimal prediction model state sequence, returned as a
(*p*+1)-by-*N _{x}*
array, where

*p*is the prediction horizon and

*N*is the number of states in the plant and unmeasured disturbance models (states from noise models are not included).

_{x}`Xopt(i,:)`

contains the calculated state values at time
`k+i-1`

, for `i = 2,...,p+1`

, where
`k`

is the current time. `Xopt(1,:)`

is the same as the current states state values.

`Topt`

— Time intervals

column vector of length *p*+1

Time intervals, returned as a column vector of length
*p*+1. `Topt(1)`

= 0, representing the
current time. Subsequent time steps `Topt(i)`

are given by
`Ts*(i-1)`

, where `Ts = MPCobj.Ts`

is
the controller sample time.

Use `Topt`

when plotting the `Uopt`

,
`Xopt`

, or `Yopt`

sequences.

`Slack`

— Slack variable

nonnegative scalar

Slack variable, ε, used in constraint softening, returned as
`0`

or a positive scalar value.

ε = 0 — All constraints were satisfied for the entire prediction horizon.

ε > 0 — At least one soft constraint is violated. When more than one constraint is violated, ε represents the worst-case soft constraint violation (scaled by your ECR values for each constraint).

See Optimization Problem for more information.

`Iterations`

— Number of solver iterations

positive integer | `0`

| `-1`

| `-2`

Number of solver iterations, returned as one of the following:

Positive integer — Number of iterations needed to solve the optimization problem that determines the optimal sequences.

`0`

— Optimization problem could not be solved in the specified maximum number of iterations.`–1`

— Optimization problem was infeasible. An optimization problem is infeasible if no solution can satisfy all the hard constraints.`–2`

— Numerical error occurred when solving the optimization problem.

`QPCode`

— Optimization solution status

`'feasible'`

| `'infeasible'`

| `'unrealiable'`

Optimization solution status, returned as one of the following:

`'feasible'`

— Optimal solution was obtained (`Iterations`

> 0)`'infeasible'`

— Solver detected a problem with no feasible solution (`Iterations`

= –1) or a numerical error occurred (`Iterations`

= –2)`'unreliable'`

— Solver failed to converge (`Iterations`

= 0). In this case, if`MPCobj.Optimizer.UseSuboptimalSolution`

is`false`

,`u`

freezes at the most recent successful solution. Otherwise, it uses the suboptimal solution found during the last solver iteration.

`Cost`

— Objective function cost

nonnegative scalar

Objective function cost, returned as a nonnegative scalar value. The cost quantifies the degree to which the controller has achieved its objectives. For more information, see Optimization Problem.

The cost value is only meaningful when ```
QPCode =
'feasible'
```

, or when `QPCode = 'feasible'`

and
`MPCobj.Optimizer.UseSuboptimalSolution`

is
`true`

.

## Tips

If the prediction model is time-invariant, use

`mpcmove`

.Use the Adaptive MPC Controller Simulink block for simulations and code generation.

## Version History

**Introduced in R2014b**

## See Also

`mpc`

| `mpcmove`

| `mpcmoveopt`

| `mpcstate`

| `review`

| `sim`

| `setEstimator`

| `getEstimator`

## Commande MATLAB

Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :

Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.

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