Main Content

# Compute Steady-State Gain

This example shows how to analyze a model predictive controller using `cloffset`. This function computes the closed-loop, steady-state gain for each output when a sustained, 1-unit disturbance is added to each output. It assumes that no constraints are active.

Define a state-space plant model.

```A = [-0.0285 -0.0014; -0.0371 -0.1476]; B = [-0.0850 0.0238; 0.0802 0.4462]; C = [0 1; 1 0]; D = zeros(2,2); CSTR = ss(A,B,C,D); CSTR.InputGroup.MV = 1; CSTR.InputGroup.UD = 2;```

Create an MPC controller for the defined plant.

`MPCobj = mpc(CSTR,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. for output(s) y1 and zero weight for output(s) y2 ```

Specify tuning weights for the measured output signals.

`MPCobj.W.OutputVariables = [1 0];`

Compute the closed-loop, steady-state gain for this controller.

`DCgain = cloffset(MPCobj)`
```-->Converting model to discrete time. -->The "Model.Disturbance" property of "mpc" object is empty: Assuming unmeasured input disturbance #2 is integrated white noise. -->Assuming output disturbance added to measured output channel #1 is integrated white noise. Assuming no disturbance added to measured output channel #2. -->The "Model.Noise" property of the "mpc" object is empty. Assuming white noise on each measured output channel. ```
```DCgain = 2×2 0 0.0000 2.3272 1.0000 ```

`DCgain(i,j)` represents the gain from the sustained, 1-unit disturbance on output `j` to measured output `i`.

The second column of `DCgain` shows that the controller does not react to a disturbance applied to the second output. This disturbance is ignored because the tuning weight for this channel is `0`.

Since the tuning weight for the first output is nonzero, the controller reacts when a disturbance is applied to this output, removing the effect of the disturbance (`DCgain(1,1) = 0`). However, since the tuning weight for the second output is `0`, this controller reaction introduces a gain for output 2 (`DCgain(2,1) = 2.3272`).

## Support

#### Implementing an Adaptive Cruise Controller with Simulink

Download technical paper