# Documentation

## Worst-Case Performance of Uncertain System

This example shows how to calculate the worst-case performance of the closed-loop system described in System with Uncertain Parameters. The following commands construct that system.

```m1 = ureal('m1',1,'percent',20); m2 = ureal('m2',1,'percent',20); k = ureal('k',1,'percent',20); s = zpk('s'); G1 = ss(1/s^2)/m1; G2 = ss(1/s^2)/m2; F = [0;G1]*[1 -1]+[1;-1]*[0,G2]; P = lft(F,k); C = 100*ss((s+1)/(.001*s+1))^3; T = feedback(P*C,1); % Closed-loop uncertain system ```

This uncertain state-space model `T` has three uncertain parameters, `k`, `m1`, and `m2`, each equal to 1±20% uncertain variation. To analyze whether the closed-loop system `T` is robustly stable for all combinations of values for these three parameters, you can execute the commands:

```[StabilityMargin,Udestab,REPORT] = robuststab(T); REPORT ```
```REPORT = Uncertain system is robustly stable to modeled uncertainty. -- It can tolerate up to 301% of the modeled uncertainty. -- A destabilizing combination of 500% of the modeled uncertainty was found. -- This combination causes an instability at 8.23 rad/seconds. -- Sensitivity with respect to the uncertain elements are: 'k' is 20%. Increasing 'k' by 25% leads to a 5% decrease in the margin. 'm1' is 60%. Increasing 'm1' by 25% leads to a 15% decrease in the margin. 'm2' is 58%. Increasing 'm2' by 25% leads to a 14% decrease in the margin. ```

The report tells you that the control system is robust for all parameter variations in the ±20% range, and that the smallest destabilizing combination of real variations in the values `k`, `m1`, and `m2` has sizes somewhere between 301% and 500% greater than ±20%, i.e., between ±62.2% and ±100%. The value `Udestab` returns an estimate of the 500% destabilizing parameter variation combination:

```Udestab ```
```Udestab = k: 1.2382e-10 m1: 9.1953e-05 m2: 6.3193e-06 ```

You have a comfortable safety margin of between 311% to 500% larger than the anticipated ±20% parameter variations before the closed loop goes unstable. But how much can closed-loop performance deteriorate for parameter variations constrained to lie strictly within the anticipated ±20% range? The following code computes worst-case peak gain of `T`, and estimates the frequency and parameter values at which the peak gain occurs:

```[PeakGain,Uwc] = wcgain(T); Twc = usubs(T,Uwc); % Worst case closed-loop system T Trand = usample(T,4); % 4 random samples of uncertain system T bodemag(Twc,'r',Trand,'b-.',{.5,50}); legend('T_{wc} - worst-case','T_{rand} - random samples',... 'Location','SouthWest'); ```