Loadflowfinal Kad Matlab Code
Loadflowfinal Kad Matlab Code
Contents
Formation of Y matrix from the given data
%{
EECE 305 Open Ended Lab
Group Members:
202116029 : K. M. Taskin Zaman Kafi
202116034 : Mahmuda Akter
202116029 : MD Abrar Shahriar Kabir
%}
clc
clear all
close all
Ymat = zeros(bus,bus);
%Finding OFF DIAGONAl elements
for m = 1:n
Ymat(b1(m),b2(m)) = Ymat(b1(m),b2(m)) - y(m);
Ymat(b2(m),b1(m)) = Ymat(b1(m),b2(m));
end
file:///G:/Anonno/MIST Documents/L3, T1/EECE 306/loadflowfinal_kad.html 1/5
6/24/23, 7:51 AM loadflowfinal_kad
%Finding the diagonal elements
for m=1:bus
for k=1:n
if b1(k)== m
Ymat(m,m) = Ymat(m,m)+y(k)+ B(k);
elseif b2(k)== m
Ymat(m,m)= Ymat(m,m)+y(k)+ B(k);
else
end
end
end
Ymat
Ymat =
Columns 1 through 4
Column 5
0.0000 + 0.0000i
-2.5000 + 7.5000i
0.0000 + 0.0000i
-1.2500 + 3.7500i
3.7500 -11.2100i
base=100;
VB = bus_data(:,2); %Bus Voltage in p.u.
PB = bus_data(:,3); %Bus Phase
P = bus_data(:,4); %Real Power of Bus
Q = bus_data(:,5); %Reactive Power of Bus
bus_n = length(bus_data(:,1));
VR = zeros(bus_n,1); %Resultant Voltage
VR = VB;
V_NEW= VR;
for jk= 1:200
for i=2:bus_n
SUM=0;
for j=1:bus_n
if i~=j
SUM= SUM+Ymat(i,j)*V_NEW(j);
end
end
VR(i) = (((((P(i)-1j*Q(i)))/base)/conj(V_NEW(i)))-SUM)/Ymat(i,i);
imaginary_part = zeros(bus_n,1);
for ph=1:bus_n
imaginary_part(ph,1)= imag(VR(ph,1));
end
real_part = zeros(bus_n,1);
for re = 1:bus_n
real_part(re,1) = real(VR(re,1));
end
V_NEW =
1.0600 + 0.0000i
1.0464 - 0.0503i
1.0187 - 0.0929i
1.0179 - 0.0978i
1.0118 - 0.1093i
VR =
1.0600 + 0.0000i
1.0464 - 0.0503i
1.0187 - 0.0929i
1.0179 - 0.0978i
1.0118 - 0.1093i
Calculation of voltage and phase angle of slack, generator and load buses
theta= zeros(bus_n,1);
for th =1:bus_n
theta(th,1) = atand(imaginary_part(th,1)/real_part(th,1));
end
fprintf('The column matrix containg Voltage Magnitude:')
magg = abs(VR);
magg
fprintf('The column matrix containg Phase:')
theta
for print=1:bus_n
fprintf('The voltage of BUS %d is %f \n ',print,magg(print,1))
end
fprintf('\n \n \n')
for print=1:bus_n
fprintf('The phase of BUS %d is %f \n ',print,theta(print,1))
end
fprintf('\n \n \n')
1.0600
1.0476
1.0229
1.0225
1.0176
0
-2.7529
-5.2086
-5.4879
-6.1672
S=0;
slack=1;
SUM=0;
for j=2:bus_n
SUM=SUM+Ymat(slack,j)*VR(j,1);
end
S=VR(slack,1)*(VR(slack,1)*Ymat(slack,slack)+SUM);
S;
P_slack= real(S)*100;
fprintf('Real power of slack bus is P= %d \n' ,P_slack)
Q_slack = imag(S)*100;
fprintf('Reactive power of slack bus is Q= %d \n' ,Q_slack)