p is the optimization direction
a0=0
b0=1
r=(3-np.sqrt(5))/2
uncert = 1e-5 # Specified uncertainty
a1= a0 + r*(b0-a0);
b1= b0 - r*(b0-a0);
while (b0-a0) > uncert:
if loss(rhs,ObsOp,t,ind_m,u0+a1*p,w,R,opt,*args) < loss(rhs,ObsOp,t,\
ind_m,u0+b1*p,w,R,opt,*args):
b0=b1;
b1=a1;
a1= a0 + r*(b0-a0);
else:
a0=a1;
a1=b1;
b1= b0 - r*(b0-a0);
alpha = (b0+a0)/2
return alpha
```
✝ ✆ **Listing 8.** Computation of the cost functional defined in Equation (13). ✞ ☎

```