0% found this document useful (0 votes)
39 views12 pages

Power System

Uploaded by

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

Power System

Uploaded by

Manish Kumawat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Name- Manish kumar

Rollno- 120EE0476
Q1. Write a MATLAB code to do load flow operation using Newton-Raphson. For the given data
below:

Bus Power Data:

Feeder Data:

Transformer Data:
Solution:

Code to store Buses:

%% General Information

no_bus = 9;
no_fd = 6;
no_tr = 3;
no_pv = 2;
Sb = 100;

%% Bus Data

bustype = [1 2 2 3 3 3 3 3 3]';
Vsp = [1 1.025 1.025 0 0 0 0 0 0]';

Pg = [0 163.0000 85.0000 0 0 0 0 0
0]'/Sb;
Qg = [0 0 0 0 0 0 0 0 0]'/Sb;
Pd = [0 0 0 0 125 90 0 100 0]'/Sb;
Qd = [ 0 0 0 0 50 30 0 35 0]'/Sb;
Bus = [1 2 3 4 5 6 7 8 9]';

slackbus = 1;

Busdata = table(Bus,Vsp,Pg,Qg,Pd,Qd,bustype);
%% Feeder Data

fd_frombus = [6 7 9 7 5 8]';
fd_tobus = [4 5 6 8 4 9]';

fd_r = [0.0170 0.0320 0.0390 0.0085 0.0100 0.0119]';


fd_x = [0.0920 0.1630 0.1700 0.0720 0.0850 0.1008]';
fd_ys = [0.1580 0.3060 0.3580 0.1490 0.1760 0.2090] * 1i ;

fd_ys = transpose(fd_ys);

Feederdata = table(fd_frombus, fd_tobus, fd_r,fd_x,fd_ys);


%% Transformer Data

tr_frombus = [2 4 3]';
tr_tobus = [7 1 9]';

tr_r = [0 0 0]';
tr_x = [0.0625 0.0576 0.0586]';
tr_alpha = [1.0 1.0204 1.0]';
TransformerBusdata = table(tr_frombus, tr_tobus, tr_r,tr_x,tr_alpha);

%% Generator Data

% generator resistance and xd are set to 0 if not a generator bus


gen_r = [0 0 0 0 0 0 0 0 0];
gen_xd = [0.0608 0.1198 0.1813 0 0 0 0 0 0];

Code To creating Y-Bus and Do NRLF operation:

clear all
close all
clc
%%

NetworkData_9Bus % acessing the bus data from the code

%%

%%Line parameter calculation


fd_z= complex(fd_r,fd_x); %calculating impedance from the data of from to to bus

fd_y= 1./fd_z; % calculating addmitance of the obtained impedance

%% calculating Y bus without transformer parameter

Y=zeros(no_bus,no_bus);

for k=1:no_fd
i=fd_frombus(k);
j=fd_tobus(k);
Y(i,i)=Y(i,i)+fd_y(k)+fd_ys(k)/2;
Y(i,j)=Y(i,j)-fd_y(k);
Y(j,i)=Y(i,j);
Y(j,j)=Y(j,j)+fd_y(k)+fd_ys(k)/2;
end

%% transformer parameter calculation

if no_tr>0
tr_z=complex(tr_r,tr_x);
tr_y=zeros(no_tr,1);
for i=1:no_tr
tr_y(i)=1/tr_z(i);
end
Y_tr=zeros(no_bus,no_bus);
for k=1:no_tr
i=tr_frombus(k);
j=tr_tobus(k);
Y_tr(i,i)=Y_tr(i,i)+tr_alpha(k)*conj(tr_alpha(k))*tr_y(k);
Y_tr(i,j)=Y_tr(i,j)-conj(tr_alpha(k))*tr_y(k);
Y_tr(j,i)=Y_tr(j,i)-tr_alpha(k)*tr_y(k);
Y_tr(j,j)=Y_tr(j,j)+tr_y(k);
end
Y=Y+Y_tr;
end
fprintf("\nY-bus matrix....\n");
disp(Y);

%%

%%Initialize voltage
V=zeros(no_bus,1);
Vm=zeros(no_bus,1);
delta=zeros(no_bus,1);

for i=1:no_bus
if bustype(i)==1 || bustype(i)==2
Vm(i)=Vsp(i);
else
Vm(i)=1;
end
end

Psp=Pg-Pd;
Qsp=Qg-Qd;

Pcal=zeros(no_bus,1);
Qcal=zeros(no_bus,1);

no_pq = no_bus - no_pv - 1;


Npq = zeros(no_pq,1);
Np = zeros(no_bus-1,1);

j=1;
for i=1:no_bus
if bustype(i) == 3
Npq(j) = i;
j = j + 1;
end
end

m=1;
for i=1:no_bus
if bustype(i)==2 || bustype(i)==3
Np(m)=i;
m=m+1;
end
end

delP=zeros(no_bus-1,1);
delQ=zeros(no_pq,1);

H=zeros(no_bus-1,no_bus-1);
N=zeros(no_bus-1,no_pq);
J=zeros(no_pq,no_bus-1);
L=zeros(no_pq,no_pq);

max_itr=10;
G=real(Y);
B=imag(Y);
for itr=1:max_itr
%% Calculate P

for i=1:no_bus
s=0;

for k=1:no_bus
s=s+Vm(i)*Vm(k)*(G(i,k)*cos(delta(i)-delta(k))
+B(i,k)*sin(delta(i)-delta(k)));
end
Pcal(i)=s;

end

%% Calculate Q
for i=1:no_bus
s=0;

for k=1:no_bus
s=s+Vm(i)*Vm(k)*(G(i,k)*sin(delta(i)-delta(k))-
B(i,k)*cos(delta(i)-delta(k)));
end
Qcal(i)=s;

end

%% Calculate delP
p=1;
for i=1:no_bus-1
j=Np(i);
delP(i)=Psp(j)-Pcal(j);
end

%% Calculate delQ
q=1;
for i=1:no_pq
j=Npq(i);
delQ(i)=Qsp(j)-Qcal(j);
end

%% H matrix
for m=1:no_bus-1
for n=1:no_bus-1
i=Np(m);
j=Np(n);
if i==j
H(m,n)=-Qcal(i)-Vm(i)*Vm(i)*B(i,i);
else
H(m,n)=Vm(i)*Vm(j)*(G(i,j)*sin(delta(i)-delta(j))-
B(i,j)*cos(delta(i)-delta(j)));
end
end
end

%% N Matrix
for m=1:no_bus-1
for n=1:no_pq
i=Np(m);
j=Npq(n);
if i==j
N(m,n)=Pcal(i)+Vm(i)*Vm(i)*G(i,i);
else
N(m,n)=Vm(i)*Vm(j)*(G(i,j)*cos(delta(i)-delta(j))
+B(i,j)*sin(delta(i)-delta(j)));
end
end
end

%% J matrix
for m=1:no_pq
for n=1:no_bus-1
i=Npq(m);
j=Np(n);
if i==j
J(m,n)=Pcal(i)-Vm(i)*Vm(i)*G(i,i);
else
J(m,n)=Vm(i)*Vm(j)*(-G(i,j)*cos(delta(i)-delta(j))-
B(i,j)*sin(delta(i)-delta(j)));
end
end
end

%% L matrix
for m=1:no_pq
for n=1:no_pq
i=Npq(m);
j=Npq(n);
if i==j
L(m,n)=Qcal(i)-Vm(i)*Vm(i)*B(i,i);
else
L(m,n)=Vm(i)*Vm(j)*(G(i,j)*sin(delta(i)-delta(j))-
B(i,j)*cos(delta(i)-delta(j)));
end
end
end
%% Jacobian matrix
Jacobian_matrix=[H N;J L];

%% Solve NRLF equation

z=[delP;delQ];

x=inv(Jacobian_matrix)*z;
%% update delta
del_delta=x(1:no_bus-1);
for i=1:no_bus-1
k = Np(i);
delta(k) = delta(k)+del_delta(i);
end

%% update voltage
del_V=x(no_bus-1+1:no_bus-1+no_pq);
for i=1:no_pq
k = Npq(i);
Vm(k) = Vm(k)+Vm(k)*del_V(i);
end

%% Calculating complex V
V=zeros(no_bus,1);
for i=1:no_bus
a=Vm(i)*cos(delta(i));
b=Vm(i)*sin(delta(i));
V(i)=complex(a,b);
end

%% convergence criteria
eps=10e-5;
if max(abs(z))<eps
fprintf("Load Flow converged in %d iterations\n",itr);
break;
end
end
delta_degree = delta*(180/pi);
%% Calculation of current injection
I_inj = Y*V;
%% Calculation of Power injection
%Apparent power injection
Si = V.*conj(I_inj);
% active Power injection
Pi = real(Si);
% reactive power injection
Qi = imag(Si);
% active power generation
Pg = Pi+Pd;
% reactive power generation
Qg = Qi+Qd;

%% Table for bus data


if no_tr>0
bus_code = [1; 2; 3; 4; 5; 6; 7; 8; 9];
Bus_data = table(bus_code,Vm,delta_degree,Pg,Qg,Pd,Qd,Pi,Qi)
end

%% Line Current Calculation


fd_I=zeros(no_fd,2);
for k=1:no_fd
i=fd_frombus(k);
j=fd_tobus(k);
fd_I(k,1)=(V(i)-V(j))*fd_y(k)+V(i)*(fd_ys(k)/2);
fd_I(k,2)=(V(j)-V(i))*fd_y(k)+V(j)*(fd_ys(k)/2);
end

%% Line Power Calculation


fd_S=zeros(no_fd,2);
for k=1:no_fd
i=fd_frombus(k);
j=fd_tobus(k);
fd_S(k,1)=(V(i))*conj(fd_I(k,1));
fd_S(k,2)=(V(j))*conj(fd_I(k,2));
end

%% Line loss calculation


fd_loss=zeros(no_fd,1);
for k=1:no_fd
fd_loss(k)=fd_S(k,1)+fd_S(k,2);
end

%% Table for feeder current and power


fd_I_from_to = abs(fd_I(:,1));
fd_I_to_from = abs(fd_I(:,2));
fd_I_to_from_c =fd_I(:,1);
fd_I_from_to_c = fd_I(:,2);
angle_fd_from_to = (angle(fd_I_from_to_c))*(180/pi);
angle_fd_to_from = (angle(fd_I_to_from_c))*(180/pi);

activefd_S_from_to = real(fd_S(:,1));
reactivefd_S_from_to = imag(fd_S(:,1));
activefd_S_to_from = real(fd_S(:,2));
reactivefd_S_to_from = imag(fd_S(:,2));

activefd_loss=real(fd_loss);
reactivefd_loss=imag(fd_loss);
if no_tr>0
Feeder_code =[1;2;3;4;5;6];
fd_frombus = [6 ; 7 ; 9 ; 7 ; 5 ; 8];
fd_tobus = [4 ; 5 ; 6 ; 8 ; 4 ; 9];
disp('Feeder current and power (both ends) using obtained voltage')

Feeder_Data =
table(Feeder_code ,fd_frombus,fd_tobus,fd_I_from_to,angle_fd_from_to,fd_I_to_from,
angle_fd_to_from,activefd_S_from_to,reactivefd_S_from_to,activefd_S_to_from,reacti
vefd_S_to_from,activefd_loss,reactivefd_loss)
end
%% Transformer current calculation
if no_tr>0
tr_I=zeros(no_tr,2);
for k=1:no_tr
i=tr_frombus(k);
j=tr_tobus(k);
tr_I(k,1) = tr_alpha(k) *conj(tr_alpha(k))* tr_y(k) * V(i) -
conj(tr_alpha(k)) * V(j)*tr_y(k);
tr_I(k,2) = -tr_alpha(k) * tr_y(k) * V(i) + tr_y(k) * V(j);
end
end
%% Transformer power calculation
if no_tr>0
tr_S=zeros(no_tr,2);
for k=1:no_tr
i=tr_frombus(k);
j=tr_tobus(k);
tr_S(k,1) = V(i) * conj(tr_I(k,1));
tr_S(k,2) = V(j) * conj(tr_I(k,2));
end
end
%% Transformer loss calculation

if no_tr>0
tr_loss=zeros(no_tr,1);
for k=1:no_tr
i=tr_frombus(k);
j=tr_tobus(k);
tr_loss(k) = tr_S(k,1) + tr_S(k,2);
end
end

%% Table for transformer current and power


if no_tr>0
tr_I_from_to = abs(tr_I(:,1));
tr_I_to_from = abs(tr_I(:,2));
tr_I_to_from_c =tr_I(:,1);
tr_I_from_to_c = tr_I(:,2);
angle_tr_from_to = (angle(tr_I_from_to_c))*(180/pi);
angle_tr_to_from = (angle(tr_I_to_from_c))*(180/pi);

activetr_S_from_to = real(tr_S(:,1));
reactivetr_S_from_to = imag(tr_S(:,1));
activetr_S_to_from =real(tr_S(:,2));
reactivetr_S_to_from = imag(tr_S(:,2));

activetr_loss=real(tr_loss);
reactivetr_loss=imag(tr_loss);

transformer_code = [7;8;9];
tr_frombus = [2 ;4; 3];
tr_tobus = [7; 1; 9];

disp('transformer current and power (both ends) using obtained voltage')


Transformer_data =
table(transformer_code,tr_frombus,tr_tobus,tr_I_from_to,angle_tr_from_to,tr_I_to_f
rom,angle_tr_to_from,activetr_S_from_to,reactivetr_S_from_to,activetr_S_to_from,re
activetr_S_to_from,activetr_loss,reactivetr_loss)
end
%% generator current

gen_I = zeros(no_bus,1);
Sd = Pd + 1i * Qd;
load_I = conj(Sd./V);
for k = 1:no_bus
if(bustype(k) ~= 3)
gen_I(k) = I_inj(k) + load_I(k);
end
end
gen_I = gen_I(gen_I ~= 0);
gen_I_injected = abs(gen_I);
angle_gen_I_inj= angle(gen_I)*(180/pi);

%% generator power
gen_loss = zeros(no_bus,1);
for k = 1:no_bus
if(bustype(k) ~= 3)
gen_loss(k) = V(k) * conj(gen_I(k));
end
end
gen_loss = gen_loss(gen_I~= 0);

Active_gen_injection=real(gen_loss);
Reactive_gen_injection=imag(gen_loss);

%% Table for generator data


if no_tr>0
disp('Generator current and power injection')
generator_bus =[1;2;3];
Generator_data =
table(generator_bus,gen_I_injected,angle_gen_I_inj,Active_gen_injection,Reactive_g
en_injection)
end
%% load power
load_loss = zeros(no_bus,1);
for k = 1:no_bus
if(bustype(k) == 3)
load_loss(k) = V(k) * conj(load_I(k));
end
end

%% Total loss
if no_tr>0
total_loss = sum([load_loss ;gen_loss ;fd_loss(:); tr_loss(:)]);
else
total_loss = sum([load_loss ;gen_loss ;fd_loss(:)]);
end
%% Total power
total_power=sum(Si);

disp('Error:Total Power-Total loss=')


disp(total_power-total_loss);

Output:

Y-Bus:
Feeder Data:
Transformer Data:

Generator Data:

You might also like