# sensitivity

Compute effect of controller tuning weights on performance

## Syntax

`[J,sens] = sensitivity(MPCobj,PerfFunc,PerfWeights,Tstop,r,v,simopt,utarget)[J,sens] = sensitivity(MPCobj,'perf_fun',param1,param2,...)`

## Description

The `sensitivity` function is a controller tuning aid. `J` specifies a scalar performance metric. `sensitivity` computes `J` and its partial derivatives with respect to the controller tuning weights. These sensitivities suggest tuning weight adjustments that should improve performance, that is, reduce `J`.

`[J,sens] = sensitivity(MPCobj,PerfFunc,PerfWeights,Tstop,r,v,simopt,utarget)` calculates the scalar performance metric, `J`, and sensitivities, `sens`, for the controller defined by the MPC controller object `MPCobj`.

`PerfFunc` must be one of the following strings:

`'ISE'` (integral squared error) for which the performance metric is

`$J=\sum _{i=1}^{Tstop}\left(\sum _{j=1}^{{n}_{y}}{\left({w}_{j}^{y}{e}_{yij}\right)}^{2}+\sum _{j=1}^{{n}_{u}}\left[{\left({w}_{j}^{u}{e}_{uij}\right)}^{2}+{\left({w}_{j}^{\Delta u}\Delta {u}_{ij}\right)}^{2}\right]\right)$`

`'IAE'` (integral absolute error) for which the performance metric is

`$J=\sum _{i=1}^{Tstop}\left(\sum _{j=1}^{{n}_{y}}|{w}_{j}^{y}{e}_{yij}|+\sum _{j=1}^{{n}_{u}}\left(|{w}_{j}^{u}{e}_{uij}|+|{w}_{j}^{\Delta u}\Delta {u}_{ij}|\right)\right)$`

`'ITSE'` (integral of time-weighted squared error) for which the performance metric is

`$J=\sum _{i=1}^{Tstop}i\Delta t\left(\sum _{j=1}^{{n}_{y}}{\left({w}_{j}^{y}{e}_{yij}\right)}^{2}+\sum _{j=1}^{{n}_{u}}\left[{\left({w}_{j}^{u}{e}_{uij}\right)}^{2}+{\left({w}_{j}^{\Delta u}\Delta {u}_{ij}\right)}^{2}\right]\right)$`
`$J=\sum _{i=1}^{Tstop}i\Delta t\left(\sum _{j=1}^{{n}_{y}}|{w}_{j}^{y}{e}_{yij}|+\sum _{j=1}^{{n}_{u}}\left(|{w}_{j}^{u}{e}_{uij}|+|{w}_{j}^{\Delta u}\Delta {u}_{ij}|\right)\right)$`

`'ITAE'` (integral of time-weighted absolute error) for which the performance metric is

In the above expressions ny is the number of controlled outputs and nu is the number of manipulated variables. eyij is the difference between output j and its setpoint (or reference) value at time interval i. euij is the difference between manipulated variable j and its target at time interval i.

The w parameters are nonnegative performance weights defined by the structure `PerfWeights`, which contains the following fields:

• `OutputVariables`ny element row vector that contains the ${w}_{j}^{y}$ values

• `ManipulatedVariables`nu element row vector that contains the ${w}_{j}^{u}$ values

• `ManipulatedVariablesRate`nu element row vector that contains the ${w}_{j}^{\Delta u}$ values

If `PerfWeights` is unspecified, it defaults to the corresponding weights in `MPCobj`. In general, however, the performance weights and those used in the controller have different purposes and should be defined accordingly.

Inputs `Tstop`, `r`, `v`, and `simopt` define the simulation scenario used to evaluate performance. See `sim` for details.

`Tstop` is the integer number of controller sampling intervals to be simulated. The final time for the simulations will be Tstop × Δt, where Δt is the controller sampling interval specified in `MPCobj`.

The optional input `utarget` is a vector of nu manipulated variable targets. Their defaults are the nominal values of the manipulated variables. Δuij is the change in manipulated variable j and its target at time interval i.

The structure variable `sens` contains the computed sensitivities (partial derivatives of `J` with respect to the `MPCobj` tuning weights.) Its fields are:

• `OutputVariables`ny element row vector of sensitivities with respect to `MPCobj.Weights.OutputVariables`

• `ManipulatedVariables`nu element row vector of sensitivities with respect to `MPCobj.Weights.ManipulatedVariables`

• `ManipulatedVariablesRate`nu element row vector of sensitivities with respect to `MPCobj.Weights.ManipulatedVariablesRate`

See Weights for details on the tuning weights contained in `MPCobj`.

`[J,sens] = sensitivity(MPCobj,'perf_fun',param1,param2,...)` employs a performance function `'perf_fun'` to define `J`. Its function definition must be in the form

`function J = perf_fun(MPCobj, param1, param2, ...)`

That is, it must compute `J` for the given controller and optional parameters `param1`, `param2`, ... and it must be on the MATLAB® path.

 Note:   While performing the sensitivity analysis, the software ignores time-varying, nondiagonal, and ECR slack variable weights.

## Examples

collapse all

### Compute Controller Performance and Sensitivity

Define a third-order plant model with three manipulated variables and two controlled outputs.

```plant = rss(3,2,3); plant.d = 0; ```

Create an MPC controller for the plant.

```MPCobj = mpc(plant,1); ```
```-->The "PredictionHorizon" property of "mpc" object is empty. Trying PredictionHorizon = 10. -->The "ControlHorizon" property of the "mpc" object is empty. Assuming 2. -->The "Weights.ManipulatedVariables" property of "mpc" object is empty. Assuming default 0.00000. -->The "Weights.ManipulatedVariablesRate" property of "mpc" object is empty. Assuming default 0.10000. -->The "Weights.OutputVariables" property of "mpc" object is empty. Assuming default 1.00000. ```

Specify an integral absolute error performance function and set the performance weights.

```PerfFunc = 'IAE'; PerfWts.OutputVariables = [1 0.5]; PerfWts.ManipulatedVariables = zeros(1,3); PerfWts.ManipulatedVariablesRate = zeros(1,3); ```

Define a `20` second simulation scenario with a unit step in the output 1 setpoint and a setpoint of zero for output 2.

```Tstop = 20; r = [1 0]; ```

Define the nominal values of the manipulated variables to be zeros.

```utarget = zeros(1,3); ```

Calculate the performance metric, `J`, and sensitivities, `sens`, for the specified controller and simulation scenario.

```[J, sens] = sensitivity(MPCobj,PerfFunc,PerfWts,Tstop,r,[],[],utarget); ```
```-->Converting model to discrete time. -->Assuming output disturbance added to measured output channel #1 is integrated white noise. -->Assuming output disturbance added to measured output channel #2 is integrated white noise. -->The "Model.Noise" property of the "mpc" object is empty. Assuming white noise on each measured output channel. ```