Calculate A and B Matrices
\begin{lstlisting}[
frame=single,
style=Matlab-Pyglike]
% M5 Assignment 1: PM Generator
Lsa = 150e-6;        %self inductance
Lma = 15e-6;         %mutual inductance
L = [Lsa, Lma, Lma;
    Lma, Lsa, Lma;
    Lma, Lma, Lsa];

rs = 9.4e-3;         %phase resistance
R = diag([rs rs rs]);

A = -inv(L)*R
B = inv(L)
\end{lstlisting}
%------------------------------------------------------------------
Calculate Phase to Neutral Voltage
\begin{lstlisting}[
frame=single,
style=Matlab-Pyglike]
function Vabc = fcn(theta_e)
Vm = 74;
va = Vm*cos(theta_e);
vb = Vm*cos(theta_e - 2*pi/3);
vc = Vm*cos(theta_e - 4*pi/3);
Vabc = [va;vb;vc];
\end{lstlisting}
Calculate Internal Generated Voltage
\begin{lstlisting}[
frame=single,
style=Matlab-Pyglike]
function Eabc = fcn(theta_e)
Em = 63;
ea = Em*cos(theta_e - 0.46);
eb = Em*cos(theta_e - 0.46 - 2*pi/3);
ec = Em*cos(theta_e - 0.46 - 4*pi/3);
Eabc = [ea;eb;ec];
\end{lstlisting}
Matlab Figure Generator
\begin{lstlisting}[
frame=single,
style=Matlab-Pyglike]
out = sim ("PM_Project_SP25.slx");
mkdir figs
xlims_zoom =[0 0.1];
figure (1)
plot (out.Iabc)
title (" Phase Currents ")
ylabel (" Current [ A ]")
legend ([" phase a " , " phase b " , " phase c "])
saveas ( gcf , 'figs/currents.png')

figure (4)
plot (out.Torque)
title (" Developed Torque ")
ylabel (" Torque ( N / m ) ")
saveas ( gcf , 'figs/torque.png')

time = out.Iabc.Time(:);
Iabc = out.Iabc.Data;     
iA = Iabc(1,:).';
iB = Iabc(2,:).';
iC = Iabc(3,:).';

figure (5)
subplot(3,1,1)
plot(time, iA)
title("Phase A Current")
ylabel("Current [A]")

subplot(3,1,2)
plot(time, iB)
title("Phase B Current")
ylabel("Current [A]")

subplot(3,1,3)
plot(time, iC)
title("Phase C Current")
ylabel("Current [A]")
xlabel('Time [s]')

saveas(gcf,'figs/currents_split.png')
\end{lstlisting}