0% found this document useful (0 votes)
5 views6 pages

Assign 2

The document contains MATLAB code for building a Bus Admittance Matrix and calculating bus voltages in a power system. It includes multiple sections with different scenarios, such as calculating voltages, currents, line losses, and slack bus power for a three-bus system. The output provides detailed results for each bus voltage, current in the lines, and power calculations.

Uploaded by

aainajain458
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

Assign 2

The document contains MATLAB code for building a Bus Admittance Matrix and calculating bus voltages in a power system. It includes multiple sections with different scenarios, such as calculating voltages, currents, line losses, and slack bus power for a three-bus system. The output provides detailed results for each bus voltage, current in the lines, and power calculations.

Uploaded by

aainajain458
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

ASSIGNMENT-2

NAME = AAINA JAIN ID = 2022UEE1052 BATCH = E2


Q1. Write a function M-file to build the Bus Admittance Matrix. In the circuit shown,
obtain Y bus E1 = 1.1 0degree and E2 = 1.0 0 degree. Obtain bus voltages.

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;

fprintf("voltage at bus 1 = %0.3f volts\n",vbus(1))


fprintf("voltage at bus 2 = %0.3f volts\n",vbus(2))
fprintf("voltage at bus 3 = %0.3f volts\n",vbus(3))
fprintf("voltage at bus 4 = %0.3f volts\n",vbus(4))

Output
y =

0.0000 - 8.5000i 0.0000 + 2.5000i 0.0000 + 5.0000i 0.0000 + 0.0000i


0.0000 + 2.5000i 0.0000 - 8.7500i 0.0000 + 5.0000i 0.0000 + 0.0000i
0.0000 + 5.0000i 0.0000 + 5.0000i 0.0000 -22.5000i 0.0000 +12.5000i
0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 +12.5000i 0.0000 -12.5000i

voltage at bus 1 = 1.050 volts


voltage at bus 2 = 1.040 volts
voltage at bus 3 = 1.045 volts
voltage at bus 4 = 1.045 volts
Q2. Fig. shows the one line diagram of a three bus system with generation at bus1. The
magnitude of the voltage at bus1 is adjusted to 1.05pu . The scheduled loads at bus2 and
bus3 are marked on the diagram . Line impedances are marked in per unit on a
100MVA base and the line charging susceptances are neglected . Write a MATLAB
program to find the following:

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;

v2 = (conj(s2)/conj(v2) - y(1,2)*v1 - y(2,3)*v3) / y(2,2);


v3 = (conj(s3)/conj(v3) - y(1,3)*v1 - y(2,3)*v2) / y(3,3);

fprintf('%2d %0.4f + j%0.4f %0.4f + j%0.4f\n', itr, real(v2), imag(v2), real(v3),


imag(v3));
end

disp("Part a answer -");


fprintf("The voltage at bus1 = %0.4f + j%0.4f pu\n", real(v1), imag(v1));
fprintf("The voltage at bus2 = %0.4f + j%0.4f pu\n", real(v2), imag(v2));
fprintf("The voltage at bus3 = %0.4f + j%0.4f pu\n", real(v3), imag(v3));
i12 = -y(1,2) * (v1 - v2); i21 = -i12;
i13 = -y(1,3) * (v1 - v3); i31 = -i13;
i23 = -y(2,3) * (v2 - v3); i32 = -i23;

disp("Part b answer -");


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));

s12 = v1 * conj(i12); s21 = v2 * conj(i21);


s13 = v1 * conj(i13); s31 = v3 * conj(i31);
s23 = v2 * conj(i23); s32 = v3 * conj(i32);

% 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);

% Slack bus power


s_slack = conj(v1) * (v1 * (-y(1,2) - y(1,3)) + (v2 * y(1,2) + v3 * y(1,3)));

activepower = real(s_slack) * 100;


reactivepower = imag(s_slack) * 100;

disp("Part c answer -");


fprintf("This is active power = %0.4f MW and reactive power = %0.4f MVAR of slack bus\n",
activepower, reactivepower);
Output
---------------------
itr v2 v3
----------------------
1 0.9825 + j-0.0310 1.0011 + j-0.0353
2 0.9816 + j-0.0520 1.0008 + j-0.0459
3 0.9808 + j-0.0578 1.0004 + j-0.0488
4 0.9803 + j-0.0594 1.0002 + j-0.0497
5 0.9801 + j-0.0598 1.0001 + j-0.0499
6 0.9801 + j-0.0599 1.0000 + j-0.0500
7 0.9800 + j-0.0600 1.0000 + j-0.0500
8 0.9800 + j-0.0600 1.0000 + j-0.0500
9 0.9800 + j-0.0600 1.0000 + j-0.0500
10 0.9800 + j-0.0600 1.0000 + j-0.0500
Part a answer -
The voltage at bus1 = 1.0500 + j0.0000 pu
The voltage at bus2 = 0.9800 + j-0.0600 pu
The voltage at bus3 = 1.0000 + j-0.0500 pu
Part b answer -
The current in line between bus1 and bus2 = 1.9000 + j-0.8000 pu
The current in line between bus2 and bus3 = -0.6400 + j0.4800 pu
The current in line between bus3 and bus1 = -2.0000 + j1.0000 pu
Losses in line between bus1 and bus2 = 8.4997 + j16.9994 MVA
Losses in line between bus1 and bus3 = 4.9999 + j14.9996 MVA
Losses in line between bus3 and bus2 = 0.7999 + j1.5999 MVA
Part c answer -
This is active power = 409.4940 MW and reactive power = -188.9958 MVAR of slack bus
Q3. Fig (a) shows the one line diagram of three bus power system with generation at
bus1 and bus3. The magnitude of voltages at bus1 is adjusted to 1.05pu. The voltage at
bus3 is fixed at 1.04 per unit with a real power generation of 200MW. A load consisting
of 400MW and 250 MVAR is taken from bus2. Line impedances are marked in per unit
on 100 MVA base and the line charging susceptances are neglected . Write a MATLAB
program to obtain the power flow solution by the Gauss-seidel method including line
flows and line losses.
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;

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 voltage at bus1 = %0.4f + j%0.4f pu\n", real(v1), imag(v1));


fprintf("The voltage at bus2 = %0.4f + j%0.4f pu\n", real(v2), imag(v2));
fprintf("The voltage at bus3 = %0.4f + j%0.4f pu\n", real(v3), imag(v3));

i12 = -y(1,2)*(v1-v2); i21 = -i12;


i13 = -y(1,3)*(v1-v3); i31 = - i13;
i23 = -y(2,3)*(v2-v3); i32 = -i23;

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));

s12 = v1*conj(i12); s21= v2*conj(i21);


s13 = v1*conj(i13) ; s31 = v3*conj(i31);
s23 = v2*conj(i23); s32 = v3*conj(i32);

%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);

%slack bus power


s_slack = (conj(v1)*(v1*(-y(1,2)-y(1,3))+(v2*y(1,2)+v3*y(1,3))));

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

0 1.374946 0.9711 - 0.0429i 1.0400 - 0.0048i

0 1.391042 0.9708 - 0.0433i 1.0400 - 0.0051i

0 1.396294 0.9707 - 0.0434i 1.0400 - 0.0051i

0 1.397825 0.9707 - 0.0435i 1.0400 - 0.0052i

0 1.398270 0.9707 - 0.0435i 1.0400 - 0.0052i

0 1.398399 0.9707 - 0.0435i 1.0400 - 0.0052i

0 1.398436 0.9707 - 0.0435i 1.0400 - 0.0052i

0 1.398447 0.9707 - 0.0435i 1.0400 - 0.0052i

0 1.398450 0.9707 - 0.0435i 1.0400 - 0.0052i

The voltage at bus1 = 1.0500 + j0.0000 pu


The voltage at bus2 = 0.9707 + j-0.0435 pu
The voltage at bus3 = 1.0400 + j-0.0052 pu
The current in line between bus1 and bus2 = 1.6627 + j-1.1508 pu
The current in line between bus2 and bus3 = -2.3346 + j1.6037 pu
The current in line between bus3 and bus1 = -0.2553 + j0.2487 pu
Losses in line between bus1 and bus2 = 8.1779 + j16.3558 MVA
Losses in line between bus1 and bus3 = 0.1270 + j0.3810 MVA
Losses in line between bus3 and bus2 = 10.0276 + j20.0552 MVA
This is active power = 201.3896 MW and reactive power = -146.9469 MVAR of slack bus

You might also like