```
# In this script, we will design a PID controller by optimization. The system model has uncertain parameters, and we pay a price not only for poor performance of the closed-loop system, but also for a high variance in the performance. In addition to this, we place a constraint on the 90:th percentile of the maximum of the sensitivity function. This way, we will get a doubly robust controller as a result :)
# We start by defining the system and some initial controller parameters
using MonteCarloMeasurements, Optim, ControlSystems, Plots
using MonteCarloMeasurements: β
p = 1 β 0.1
ΞΆ = 0.3 β 0.05
Ο = 1 β 0.1
P = tf([p*Ο], [1, 2ΞΆ*Ο, Ο^2])
w = exp10.(LinRange(-2,3,100))
params = [1,0.1,0.1]
Msc = 1.5 # Constraint on Ms
# We now define the cost function, which includes the constraint on the maximum sensitivity function
function cost(params)
kp,ki,kd = params
C = pid(kp=kp,ki=ki,kd=kd)
G = feedback(P*C) # Closed-loop system
S = 1/(1 + P*C) # Sensitivity function
local Gd
try
```

This file has been truncated. show original