Solution

clearvars
format short
 
vVect = [toRect(1, 0); toRect(0.9629, -2.76); toRect(0.9597, -3.58); toRect(0.9742, -3.96)]
vVect = 4×1 complex
1.0000 + 0.0000i 0.9618 - 0.0464i 0.9578 - 0.0599i 0.9719 - 0.0673i
% prove toRect() works fine
% getPolar() is old and working function from
% https://medogan.com/blogs/2022/06/06/
% transmission_line_analysis/transmission_line_sending_edge_vi.html
 
for v = vVect'
getPolar(v')
end
ans = "1.0000∠0.0000e+00°"
ans = "0.9629∠-2.7600°"
ans = "0.9597∠-3.5800°"
ans = "0.9742∠-3.9600°"
testingMatrixEdition = getPolarMatrix(vVect)
testingMatrixEdition = 4×1 cell
'1.0000∠0.0000e+00°'
'0.9629∠-2.7600°'
'0.9597∠-3.5800°'
'0.9742∠-3.9600°'

a)

% transformer
a = 0.98;
y_tr = 1/(j*0.08);
y1 = y_tr/a;
y2 = y_tr*((1 - a)/(a^2));
y3 = y_tr*((a - 1)/a);
 
% shunt susceptances between nodes and gnd
shunt1 = j*0.125 + j*0.1;
shunt2 = j*0.1 + y2;
shunt3 = j*0.125 + j*0.5;
shunt4 = y3;
 
line12 = getAntiDia(0.02, 0.06);
line13 = getAntiDia(0.02, 0.06);
line23 = getAntiDia(0.05, 0.10);
line24 = -y1;
 
yBus = [shunt1-(line12+line13), line12, line13, 0;
line12, shunt2-(line12+line23+line24), line23, line24;
line13, line23, shunt3-(line13+line23), 0;
0, line24, 0, shunt4-line24
]
yBus = 4×4 complex
10.0000 -29.7750i -5.0000 +15.0000i -5.0000 +15.0000i 0.0000 + 0.0000i -5.0000 +15.0000i 9.0000 -35.9154i -4.0000 + 8.0000i 0.0000 +12.7551i -5.0000 +15.0000i -4.0000 + 8.0000i 9.0000 -22.3750i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 +12.7551i 0.0000 + 0.0000i 0.0000 -12.5000i
yBusPol = getPolarMatrix(yBus)
yBusPol = 4×4 cell
'31.4094∠-71.4353°' '15.8114∠108.4349°''15.8114∠108.4349°' '0.0000e+00∠0.0000e+00°'
'15.8114∠108.4349°' '37.0259∠-75.9320°''8.9443∠116.5651°' '12.7551∠90.0000°'
'15.8114∠108.4349°' '8.9443∠116.5651°' '24.1172∠-68.0883°' '0.0000e+00∠0.0000e+00°'
'0.0000e+00∠0.0000e+00°''12.7551∠90.0000°' '0.0000e+00∠0.0000e+00°''12.5000∠-90.0000°'

b)

iVect = yBus*vVect
iVect = 4×1 complex
1.9963 - 0.4494i -0.5030 + 0.3385i -1.1966 + 0.9090i -0.2496 + 0.1192i
sVect = (vVect).*(conj(iVect))
sVect = 4×1 complex
1.9963 + 0.4494i -0.4994 - 0.3023i -1.2006 - 0.7990i -0.2506 - 0.0991i
sVectPol = getPolarMatrix(sVect)
sVectPol = 4×1 cell
'2.0463∠12.6862°'
'0.5838∠-148.8155°'
'1.4422∠-146.3573°'
'0.2695∠-158.4276°'
function val = toRect(magnitude, angleDrg)
[real, imag] = pol2cart(deg2rad(angleDrg), magnitude);
val = complex(real, imag);
end
 
function strToReturn = getPolar(var)
precision = 4;
r = abs(var); theta_deg = rad2deg(angle(var));
if (abs(r) < 0.1 || abs(r) > 1e3) % display in exponential form
rstr = num2str(r, "%." + num2str(precision, '%d') + "e");
else
rstr = num2str(r, "%." + num2str(precision, '%d') + "f");
end
if (abs(theta_deg) < 0.1) % display in exponential form
thetaStr = num2str(theta_deg, "%." + num2str(precision, '%d') + "e");
else
thetaStr = num2str(theta_deg, "%." + num2str(precision, '%d') + "f");
end
strToReturn = rstr + "∠" + thetaStr + "°";
end
 
function cellToReturn = getPolarMatrix(matrix)
mSize = size(matrix);
cellToReturn = cell(mSize);
for i = 1:1:mSize(1)
for j = 1:1:mSize(2)
cellToReturn(i, j) = cellstr(getPolar(matrix(i, j)));
end
end
end
 
function resToReturn = getAntiDia(r, x)
z = complex(r, x);
y = 1/z;
resToReturn = -y;
end