Inductance of Motor
\begin{lstlisting}[
frame=single,
style=Matlab-Pyglike]
function L = fcn(theta)

aa = 0.1431e-1;
a4 = 0.1068e-1*cos(4*theta + 0.4272e1);
a8 = 0.3517e-3*cos(8*theta + 0.2084e2);
a12 = 0.5599e-3*cos(12*theta + 0.5148e2);
a16 = 0.4487e-3*cos(16*theta + 0.1744e2);
a20 = 0.1866e-3*cos(20*theta - 0.2523e2);
a24 = 0.1429e-3*cos(24*theta - 0.6382e2);
a28 = 0.3222e-4*cos(28*theta + 0.2141e2);
a32 = 0.1237e-3*cos(32*theta - 0.1178e2);

La = aa + a4 + a8 + a12 + a16 + a20 + a24 + a28 + a32;

%----------------------------------------------------------
bb = 0.1431e-1;
b4 = 0.1068e-1*cos(4*theta + 0.4272e1 - 2*pi/3);
b8 = 0.3517e-3*cos(8*theta + 0.2084e2 - 2*pi/3);
b12 = 0.5599e-3*cos(12*theta + 0.5148e2 - 2*pi/3);
b16 = 0.4487e-3*cos(16*theta + 0.1744e2 - 2*pi/3);
b20 = 0.1866e-3*cos(20*theta - 0.2523e2 - 2*pi/3);
b24 = 0.1429e-3*cos(24*theta - 0.6382e2 - 2*pi/3);
b28 = 0.3222e-4*cos(28*theta + 0.2141e2 - 2*pi/3);
b32 = 0.1237e-3*cos(32*theta - 0.1178e2 - 2*pi/3);

Lb = bb + b4 + b8 + b12 + b16 + b20 + b24 + b28 + b32;

%----------------------------------------------------------

cc = 0.1431e-1;
c4 = 0.1068e-1*cos(4*theta + 0.4272e1 - 4*pi/3);
c8 = 0.3517e-3*cos(8*theta + 0.2084e2 - 4*pi/3);
c12 = 0.5599e-3*cos(12*theta + 0.5148e2 - 4*pi/3);
c16 = 0.4487e-3*cos(16*theta + 0.1744e2 - 4*pi/3);
c20 = 0.1866e-3*cos(20*theta - 0.2523e2 - 4*pi/3);
c24 = 0.1429e-3*cos(24*theta - 0.6382e2 - 4*pi/3);
c28 = 0.3222e-4*cos(28*theta + 0.2141e2 - 4*pi/3);
c32 = 0.1237e-3*cos(32*theta - 0.1178e2 - 4*pi/3);

Lc = cc + c4 + c8 + c12 + c16 + c20 + c24 + c28 + c32;

%----------------------------------------------------------

L = diag([La, Lb, Lc]);
\end{lstlisting} 
\newpage
Rate of Change Inductance with Respect to Theta of Motor
\begin{lstlisting}[
frame=single,
style=Matlab-Pyglike]
function dL = fcn(theta)

da4 =  -4  * 0.1068e-1 * sin(4*theta + 0.4272e1);
da8 =  -8  * 0.3517e-3 * sin(8*theta + 0.2084e2);
da12 = -12 * 0.5599e-3 * sin(12*theta + 0.5148e2);
da16 = -16 * 0.4487e-3 * sin(16*theta + 0.1744e2);
da20 = -20 * 0.1866e-3 * sin(20*theta - 0.2523e2);
da24 = -24 * 0.1429e-3 * sin(24*theta - 0.6382e2);
da28 = -28 * 0.3222e-4 * sin(28*theta + 0.2141e2);
da32 = -32 * 0.1237e-3 * sin(32*theta - 0.1178e2);

dLa = da4 + da8 + da12 + da16 + da20 + da24 + da28 + da32;

db4 =  -4  * 0.1068e-1 * sin(4*theta + 0.4272e1 - 2*pi/3);
db8 =  -8  * 0.3517e-3 * sin(8*theta + 0.2084e2 - 2*pi/3);
db12 = -12 * 0.5599e-3 * sin(12*theta + 0.5148e2 - 2*pi/3);
db16 = -16 * 0.4487e-3 * sin(16*theta + 0.1744e2 - 2*pi/3);
db20 = -20 * 0.1866e-3 * sin(20*theta - 0.2523e2 - 2*pi/3);
db24 = -24 * 0.1429e-3 * sin(24*theta - 0.6382e2 - 2*pi/3);
db28 = -28 * 0.3222e-4 * sin(28*theta + 0.2141e2 - 2*pi/3);
db32 = -32 * 0.1237e-3 * sin(32*theta - 0.1178e2 - 2*pi/3);

dLb = db4 + db8 + db12 + db16 + db20 + db24 + db28 + db32;

dc4 =  -4  * 0.1068e-1 * sin(4*theta + 0.4272e1 - 4*pi/3);
dc8 =  -8  * 0.3517e-3 * sin(8*theta + 0.2084e2 - 4*pi/3);
dc12 = -12 * 0.5599e-3 * sin(12*theta + 0.5148e2 - 4*pi/3);
dc16 = -16 * 0.4487e-3 * sin(16*theta + 0.1744e2 - 4*pi/3);
dc20 = -20 * 0.1866e-3 * sin(20*theta - 0.2523e2 - 4*pi/3);
dc24 = -24 * 0.1429e-3 * sin(24*theta - 0.6382e2 - 4*pi/3);
dc28 = -28 * 0.3222e-4 * sin(28*theta + 0.2141e2 - 4*pi/3);
dc32 = -32 * 0.1237e-3 * sin(32*theta - 0.1178e2 - 4*pi/3);

dLc = dc4 + dc8 + dc12 + dc16 + dc20 + dc24 + dc28 + dc32;

dL = diag([dLa, dLb, dLc]);
\end{lstlisting}
\newpage
Figure Generator
\begin{lstlisting}[
frame=single,
style=Matlab-Pyglike]
% Output plots from Simulink

out=sim("M5_group_v10.slx")

%%

mkdir figs

xlims_zoom=[1.75 2]

figure(1)
plot(out.iabc)
title("Phase Currents")
ylabel("Current [A]")
legend(["phase a", "phase b", "phase c"])
saveas(gcf,'figs/currents.png')
xlim(xlims_zoom)
saveas(gcf,'figs/currents_zoom.png')

figure(2)
subplot(3,1,1)
plot(out.va)
title("Voltage phase a")
ylabel("Voltage phase a [V]")

subplot(3,1,2)
plot(out.vb)
title("Voltage phase b")
ylabel("Voltage phase b [V]")

subplot(3,1,3)
plot(out.vc)
title("Voltage phase c")
ylabel("Voltage phase c [V]")

saveas(gcf,'figs/voltages.png')
subplot(3,1,1)
xlim(xlims_zoom)
subplot(3,1,2)
xlim(xlims_zoom)
subplot(3,1,3)
xlim(xlims_zoom)
saveas(gcf,'figs/voltages_zoom.png')

figure(3)
plot(out.w)
title("Rotor Speed [rev/min]")
saveas(gcf,'figs/speed.png')
xlim(xlims_zoom)
saveas(gcf,'figs/speed_zoom.png')

figure(4)
plot(out.trq_dev)
title("Developed Torque")
saveas(gcf,'figs/torque.png')
xlim(xlims_zoom)
saveas(gcf,'figs/torque_zoom.png')
\end{lstlisting}
