# Compute Steady-State Gain

This example shows how to analyze the steady-state performance of a model predictive controller using `cloffset`. This command assumes that no constraint is active, and calculates the steady-state output sensitivity matrix of the closed loop, which is the DC gain from plant output disturbances (using a sustained 1-unit disturbance step) to controlled plant outputs. When this matrix is zero the controller is able to reject constant output disturbances and track constant setpoint with zero offsets in steady-state.

Define a state-space plant model with two inputs and two outputs. This plant represents the linearized model of a Continuously Stirred Tank Reactor (CSTR) where the first measured output is the concentration of a key reactant, the second measured output is the temperature in the reactor. For more information see CSTR 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, with a sampling time of one second.

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

As the last output line specifies, the cost function default output weights is `1` for the first output and `0` for the second one:

`MPCobj.W.OutputVariables`
```ans = 1×2 1 0 ```

The software automatically adds an integrator as output disturbance model for each measured output, in order of decreasing output weight, unless this causes the plant state to become unobservable. For this plant, only an integrator on the first output is added:

`getoutdist(MPCobj)`
```-->Converting model to discrete time. -->The "Model.Disturbance" property 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 is empty. Assuming white noise on each measured output. ans = A = x1 x1 1 B = u1 x1 1 C = x1 MO1 1 MO2 0 D = u1 MO1 0 MO2 0 Sample time: 1 seconds Discrete-time state-space model. ```

Compute the closed-loop, steady-state gain matrix for the closed loop system.

`DCgain = cloffset(MPCobj)`
```DCgain = 2×2 -0.0000 0.0000 2.3272 1.0000 ```

`DCgain(i,j)` is the closed loop static gain from output disturbance `j` to controlled plant output `i`. The first column of `DCgain` shows that a disturbance applied to the first measured output (key reactant concentration) only affects the second output (reactor temperature). The second column shows that a disturbance applied to the second measured output passes unmitigated through the closed loop and is fully measured at the second plant output. In other words, the closed loop is not able to compensate for a disturbance applied to the second output.

The fact that both entries in the first row of `DCgain` are zeros means that the controller is able to completely reject disturbances that affect this output (and therefore the tracking of any given setpoint reference on this output would be perfect). This happens because the cost function weight for the first output is nonzero, and because the built-in estimator includes the integrator added as disturbance model on the first output.

On the other hand, since the cost function weight for the second output is `0`, (and also because there is no integrator added as a disturbance model on this output) the controller does not try to reject disturbances affecting the second output, as shown by the second row of `DCgain`. This also means that the controller would be unable to track any reference setpoint on this output.