Assign 2
Assign 2
Ans
function[Y] = ybus(zdata)
fbus = zdata(:,1);
tbus = zdata(:,2);
r = zdata(:,3);
x = zdata(:,4);
nbr = length(zdata(:,1));
nbus = max(max(fbus),max(tbus));
z = r + j*x;
y = ones(nbr,1)./z;
Y = zeros(nbus,nbus);
for k = 1:nbr
if fbus(k)>0 && tbus(k)>0
Y(fbus(k),tbus(k)) = Y(fbus(k),tbus(k)) - y(k);
Y(tbus(k),fbus(k)) = Y(fbus(k),tbus(k));
end
end
for n = 1:nbus
for k = 1:nbr
if fbus(k) == n || tbus(k) == n
Y(n,n) = Y(n,n) + y(k);
end
end
end
Main Code
clc;
clear;
% from to r xl;
z = [0 1 0 1.0
0 2 0 0.8
1 2 0 0.4
1 3 0 0.2
2 3 0 0.2
3 4 0 0.08];
y = ybus(z)
zbus = inv(y);
ibus = [-j*1.1; -j*1.25; 0; 0];
vbus = zbus*ibus;
Output
y =
Ans
clc
clear
z = [1 2 0.02 0.04
1 3 0.01 0.03
2 3 0.0125 0.025];
[y] = ybus(z);
v1 = 1.05 + j*0;
v2 = 1 + j*0;
v3 = 1 + j*0;
s2 = -2.566 - j*1.102;
s3 = -1.386 - j*0.452;
itr = 0;
disp('---------------------');
disp('itr v2 v3');
disp('----------------------');
for i = 1:10
itr = itr + 1;
% Line losses
s_line12 = s12 + s21;
s_line13 = s13 + s31;
s_line23 = s23 + s32;
fprintf("Losses in line between bus1 and bus2 = %0.4f + j%0.4f MVA\n", real(s_line12) *
100, imag(s_line12) * 100);
fprintf("Losses in line between bus1 and bus3 = %0.4f + j%0.4f MVA\n", real(s_line13) *
100, imag(s_line13) * 100);
fprintf("Losses in line between bus3 and bus2 = %0.4f + j%0.4f MVA\n", real(s_line23) *
100, imag(s_line23) * 100);
[y] = ybus(z);
v1 = 1.05 + j*0;
itr =0;
s2 = -4 -j*2.5;
p3 = 2;
v2 = 1 +j*0;
vm3=1.04;
v3 = 1.04 + j*0;
for i = 1:10
v2 = (conj(s2)/conj(v2)-y(1,2)*v1 -y(2,3)*v3)/y(2,2);
q3 = -imag(conj(v3)*(y(3,3)*v3 +y(1,3)*v1 + y(2,3)*v2));
if (q3>1 || q3<0)
if q3<0
s3=p3 +j*0;
else
s3=p3 +j*1;
end
vc3 = (conj(s3)/conj(v3)-y(1,3)*v1 -y(2,3)*v2)/(y(3,3));
vi3 = imag(vc3);
vr3 = sqrt(vm3^2 - vi3^2);
v3 = vr3 + j*vi3;
end
fprintf('%4d %4f\t',itr,q3),disp([v2,v3])
end
fprintf("The current in line between bus1 and bus2 = %0.4f + j%0.4f pu\n", real(i12),
imag(i12));
fprintf("The current in line between bus2 and bus3 = %0.4f + j%0.4f pu\n", real(i23),
imag(i23));
fprintf("The current in line between bus3 and bus1 = %0.4f + j%0.4f pu\n", real(i31),
imag(i31));
%line losses
s_line12 = s12 + s21;
s_line13 = s13 + s31;
s_line23 = s23 + s32;
fprintf("Losses in line between bus1 and bus2 = %0.4f + j%0.4f MVA\n", real(s_line12) *
100, imag(s_line12) * 100);
fprintf("Losses in line between bus1 and bus3 = %0.4f + j%0.4f MVA\n", real(s_line13) *
100, imag(s_line13) * 100);
fprintf("Losses in line between bus3 and bus2 = %0.4f + j%0.4f MVA\n", real(s_line23) *
100, imag(s_line23) * 100);
activepower = real(s_slack)*100;
reactivepower = imag(s_slack)*100;
fprintf("This is active power = %0.4f MW and reactive power = %0.4f MVAR of slack bus\n",
activepower, reactivepower);
Output
0 1.160000 0.9746 - 0.0423i 1.0400 - 0.0043i