# Documentation

## MIMO Robustness Analysis

The previous sections focused on simple uncertainty models of single-input and single-output systems, predominantly from a transfer function perspective. You can also create uncertain state-space models made up of uncertain state-space matrices. Moreover, all the analysis tools covered thus far can be applied to these systems as well.

Consider, for example, a two-input, two-output, two-state system whose model has parametric uncertainty in the state-space matrices. First create an uncertain parameter `p`. Using the parameter, make uncertain `A` and `C` matrices. The `B` matrix happens to be not-uncertain, although you will add frequency-domain input uncertainty to the model later.

```p = ureal('p',10,'Percentage',10); A = [0 p;-p 0]; B = eye(2); C = [1 p;-p 1]; H = ss(A,B,C,[0 0;0 0]) ```

```H = Uncertain continuous-time state-space model with 2 outputs, 2 inputs, 2 states. The model uncertainty consists of the following blocks: p: Uncertain real, nominal = 10, variability = [-10,10]%, 2 occurrences Type "H.NominalValue" to see the nominal value, "get(H)" to see all properties, and "H.Uncertainty" to interact with the uncertain elements. ```

You can view the properties of the uncertain system `H` using the `get` command.

```get(H) ```

``` a: [2x2 umat] b: [2x2 double] c: [2x2 umat] d: [2x2 double] e: [] StateName: {2x1 cell} StateUnit: {2x1 cell} NominalValue: [2x2 ss] Uncertainty: [1x1 struct] InternalDelay: [0x1 double] InputDelay: [2x1 double] OutputDelay: [2x1 double] Ts: 0 TimeUnit: 'seconds' InputName: {2x1 cell} InputUnit: {2x1 cell} InputGroup: [1x1 struct] OutputName: {2x1 cell} OutputUnit: {2x1 cell} OutputGroup: [1x1 struct] Name: '' Notes: {} UserData: [] SamplingGrid: [1x1 struct] ```

Most properties behave in the same way as the corresponding properties of `ss` objects. The property `NominalValue` is itself an `ss` object.

### Adding Independent Input Uncertainty to Each Channel

The model for `H` does not include actuator dynamics. Said differently, the actuator models are unity-gain for all frequencies.

Nevertheless, the behavior of the actuator for channel 1 is modestly uncertain (say 10%) at low frequencies, and the high-frequency behavior beyond 20 rad/s is not accurately modeled. Similar statements hold for the actuator in channel 2, with larger modest uncertainty at low frequency (say 20%) but accuracy out to 45 rad/s.

Use `ultidyn` objects `Delta1` and `Delta2` along with shaping filters `W1` and `W2` to add this form of frequency domain uncertainty to the model.

```W1 = makeweight(.1,20,50); W2 = makeweight(.2,45,50); Delta1 = ultidyn('Delta1',[1 1]); Delta2 = ultidyn('Delta2',[1 1]); G = H*blkdiag(1+W1*Delta1,1+W2*Delta2) ```
```G = Uncertain continuous-time state-space model with 2 outputs, 2 inputs, 4 states. The model uncertainty consists of the following blocks: Delta1: Uncertain 1x1 LTI, peak gain = 1, 1 occurrences Delta2: Uncertain 1x1 LTI, peak gain = 1, 1 occurrences p: Uncertain real, nominal = 10, variability = [-10,10]%, 2 occurrences Type "G.NominalValue" to see the nominal value, "get(G)" to see all properties, and "G.Uncertainty" to interact with the uncertain elements. ```

Note that `G` is a two-input, two-output uncertain system, with dependence on three uncertain elements, `Delta1`, `Delta2`, and `p`. It has four states, two from `H` and one each from the shaping filters `W1` and `W2`, which are embedded in `G`.

You can plot a 2-second step response of several samples of `G` The 10% uncertainty in the natural frequency is obvious.

```stepplot(G,2) ```

You can create a Bode plot of samples of `G`. The high-frequency uncertainty in the model is also obvious. For clarity, start the Bode plot beyond the resonance.

```bodeplot(G,{13 100}) ```

### Closed-Loop Robustness Analysis

Load the controller and verify that it is two-input and two-output.

```load mimoKexample size(K) ```
```Warning: Updating objects saved with previous MATLAB version... Resave your MAT files to improve loading speed. State-space model with 2 outputs, 2 inputs, and 9 states. ```

You can use the command `loopsens` to form all the standard plant/controller feedback configurations, including sensitivity and complementary sensitivity at both the input and output. Because `G` is uncertain, all the closed-loop systems are uncertain as well.

```F = loopsens(G,K) ```
```F = Si: [2x2 uss] Ti: [2x2 uss] Li: [2x2 uss] So: [2x2 uss] To: [2x2 uss] Lo: [2x2 uss] PSi: [2x2 uss] CSo: [2x2 uss] Poles: [13x1 double] Stable: 1 ```

`F` is a structure with many fields. The poles of the nominal closed-loop system are in `F.Poles`, and `F.Stable` is 1 if the nominal closed-loop system is stable. In the remaining 10 fields, `S` stands for sensitivity, `T` or complementary sensitivity, and `L` for open-loop gain. The suffixes `i` and `o` refer to the input and output of the plant. Finally, `P` and `C` refer to the plant and controller.

Hence, `Ti` is mathematically the same as:

`Lo` is `G*K`, and `CSo` is mathematically the same as

Examine the transmission of disturbances at the plant input to the plant output by plotting responses of `F.PSi`. Graph some samples along with the nominal.

```bodemag(F.PSi.NominalValue,'r+',F.PSi,'b-',{1e-1 100}) ```

### Nominal Stability Margins

You can use `loopmargin` o investigate loop-at-a-time gain and phase margins, loop-at-a-time disk margins, and simultaneous multivariable margins. They are computed for the nominal system and do not reflect the uncertainty models within `G`.

Explore the simultaneous margins individually at the plant input, individually at the plant output, and simultaneously at both input and output.

```[I,DI,SimI,O,DO,SimO,Sim] = loopmargin(G,K); ```

The third output argument is the simultaneous gain and phase variations allowed in all input channels to the plant.

```SimI ```
```SimI = GainMargin: [0.1179 8.4796] PhaseMargin: [-76.5484 76.5484] Frequency: 6.3496 ```

This information implies that the gain at the plant input can vary in both channels independently by factors between (approximately) 1/8 and 8, as well as phase variations up to 76 degrees.

The sixth output argument is the simultaneous gain and phase variations allowed in all output channels to the plant.

```SimO ```
```SimO = GainMargin: [0.1190 8.4013] PhaseMargin: [-76.4242 76.4242] Frequency: 19.5393 ```

Note that the simultaneous margins at the plant output are similar to those at the input. This is not always the case in multiloop feedback systems.

The last output argument is the simultaneous gain and phase variations allowed in all input and output channels to the plant. As expected, when you consider all such variations simultaneously, the margins are somewhat smaller than those at the input or output alone.

```Sim ```
```Sim = GainMargin: [0.5660 1.7667] PhaseMargin: [-30.9788 30.9788] Frequency: 9.2914 ```

Nevertheless, these numbers indicate a generally robust closed-loop system, able to tolerate significant gain (more than +/-50% in each channel) and 30 degree phase variations simultaneously in all input and output channels of the plant.

### Robustness of Stability Model Uncertainty

With `loopmargin`, you determined various margins of the nominal, multiloop system. These margins are computed only for the nominal system, and do not reflect the uncertainty explicitly modeled by the `ureal` and `ultidyn` objects. When you work with detailed, complex uncertain system models, the conventional margins computed by `loopmargin` might not always be indicative of the actual stability margins associated with the uncertain elements. You can use `robuststab` to check the stability margin of the system to these specific modeled variations.

In this example, use `robuststab` to compute the stability margin of the closed-loop system represented by `Delta1`, `Delta2`, and `p`.

Use any of the closed-loop systems within `F = loopsens(G,K)`. All of them, `F.Si, F.To`, etc., have the same internal dynamics, and hence the stability properties are the same.

```[stabmarg,desgtabu,report] = robuststab(F.So); stabmarg ```
```stabmarg = LowerBound: 2.2174 UpperBound: 2.2175 DestabilizingFrequency: 13.5963 ```
```report ```
```report = Uncertain system is robustly stable to modeled uncertainty. -- It can tolerate up to 222% of the modeled uncertainty. -- A destabilizing combination of 222% of the modeled uncertainty was found. -- This combination causes an instability at 13.6 rad/seconds. -- Sensitivity with respect to the uncertain elements are: 'Delta1' is 55%. Increasing 'Delta1' by 25% leads to a 14% decrease in the margin. 'Delta2' is 54%. Increasing 'Delta2' by 25% leads to a 14% decrease in the margin. 'p' is 39%. Increasing 'p' by 25% leads to a 10% decrease in the margin. ```

This analysis confirms what the `loopmargin` analysis suggested. The closed-loop system is quite robust, in terms of stability, to the variations modeled by the uncertain parameters `Delta1`, `Delta2`, and `p`. In fact, the system can tolerate more than twice the modeled uncertainty without losing closed-loop stability.

### Worst-Case Gain Analysis

You can plot the Bode magnitude of the nominal output sensitivity function. It clearly shows decent disturbance rejection in all channels at low frequency.

```bodemag(F.So.NominalValue,{1e-1 100}) ```

You can compute the peak value of the maximum singular value of the frequency response matrix using `norm`.

```[PeakNom,freq] = norm(F.So.NominalValue,'inf') ```
```PeakNom = 1.1288 freq = 6.7969 ```

The peak is about 1.13, occurring at a frequency of 36 rad/s. What is the maximum output sensitivity gain that is achieved when the uncertain elements `Delta1`, `Delta2`, and `p` vary over their ranges? You can use `wcgain` to answer this.

```[maxgain,wcu] = wcgain(F.So); ```

The analysis indicates that the worst-case gain is somewhere between 2.1 and 2.2. The frequency where the peak is achieved is about 8.5.

You can replace the values for `Delta1`, `Delta2`, and `p` that achieve the gain of 2.1, using `usubs`. . Make the substitution in the output complementary sensitivity, and do a step response.

```step(F.To.NominalValue,usubs(F.To,wcu),5) ```

The perturbed response, which is the worst combination of uncertain values in terms of output sensitivity amplification, does not show significant degradation of the command response. The settling time is increased by about 50%, from 2 to 4, and the off-diagonal coupling is increased by about a factor of about 2, but is still quite small.

You can also examine the worst-case frequency response alongside the nominal and sampled systems using `wcgainplot`.

```wcgainplot(F.To,{1e-1,100}) ```