**Appendix B**

The appendix contains computer codes inserted into the InifFcn callback and StopFcn call back, respectively. Together with figures, implementation of Equations (1), (31)–(46), this is the only computer code needed to achieve the results presented in this manuscript.


**Includes classical feedback tuning methods**

clear all; close all; clc;

```
% Initialize variables and matrices for assembly of results
timestep = 0.01; theta0 = 0; omega0 = 0; thetaD = 1; omegaD = 0; J = 1;
MeanAngleNoise = 0; STDAngleNoise = 0.01; VarianceAngleNoise = (STDAngleNoise)ˆ2/sqrt(timestep);
MeanRateNoise = 0; STDRateNoise = 0.01; VarianceRateNoise=(STDRateNoise)ˆ2/sqrt(timestep);
```
### **% PID: Rule of thumb**

Kp = 1; Kd = 6.5; Ki = 5; A = [0 1; 0 0]; B = [0;1]; C = [10]; D = 0; Q = ones(2,2); R = 1\*ones(1);

**% PD: Ziegler-Nichols tuning for manually tuning PD** %[NUM,DEN] = ss2tf(A,B,C,D); G = tf(NUM,DEN); C = tf([Kd Kp],[1]); sisotool(G,C)

**% PD: Linear Quadratic Regulator** %K = lqr(A,B,Q,R); Kp = K(1); Kd = K(2); Ki = 0; % J = 76 (ish) Kp = 1; Kd = 1.7321; Ki = 0;

**% P + V: Tuning for performance specification**

tr = 0.3; ts = 2; wn = 1.8/tr; zeta = 4.6/(ts\*2.4); Kp = wnˆ2; Kv = 2\*zeta\*wn;

**Algorithm A2.** StopFcn callbacks for SIMULINK model depicted in Figures

% Printing scripts

theta = squeeze(out.theta); omega = squeeze(out.omega); t = squeeze(out.tout); J = squeeze(out.J); u = squeeze(out.u);

```
qxv = squeeze(out.qxv); a = squeeze(qxv(1,:)); b = squeeze(qxv(2,:));
thetaText = ['\theta(t) J=', num2str(J(end)), ': ', '\theta(t_f)= ', num2str(theta(end))];
omegaText = ['\omega(t) J=', num2str(J(end)), ': ', '\omega(t_f)= ', num2str(omega(end))];
ControlText = ['\mu_u_(_t_)=', num2str(mean(u)) ];
```

```
figure(1); plot(t,theta, ':', 'LineWidth', 2); hold on; plot(t,omega, '–', 'LineWidth', 2); hold off;
legend(thetaText, omegaText, 'FontSize',16, 'FontName','Palatino Linotype');
set(gca, 'FontSize',16, 'FontName','Palatino Linotype');grid;
```

```
figure(2); plot(t,a, ':', 'LineWidth', 2); hold on; plot(t,b, ':', 'LineWidth', 2); hold off;
legendtexta=['\mu_a=', num2str(mean(a))]; legendtextb=['\mu_b=', num2str(mean(b))]
legend(legendtexta,legendtextb,'FontSize',16, 'FontName','Palatino Linotype');
set(gca, 'FontSize',16, 'FontName','Palatino Linotype');grid; axis([0,1,-12.1,6.1])
```
figure(3); plot(t,u,'LineWidth', 2); legend(ControlText, 'FontSize',16, 'FontName','Palatino Linotype'); set(gca, 'FontSize',16, 'FontName','Palatino Linotype');grid;
