0% found this document useful (0 votes)
4 views2 pages

Code Print NRLF

The document contains a MATLAB function named NRLF that calculates power flow in a power system using Newton-Raphson method. It processes bus data to compute real and reactive power differences, constructs the Jacobian matrix, and iteratively calculates power values until convergence is reached. Key variables include bus numbers, power demand and generation, and the admittance matrix.
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)
4 views2 pages

Code Print NRLF

The document contains a MATLAB function named NRLF that calculates power flow in a power system using Newton-Raphson method. It processes bus data to compute real and reactive power differences, constructs the Jacobian matrix, and iteratively calculates power values until convergence is reached. Key variables include bus numbers, power demand and generation, and the admittance matrix.
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/ 2

4/3/25 12:37 PM C:\Users\lenovo\Desktop\NRLF.

m 1 of 2

function NRLF=NRLF(nb)
bus=BUSDATA(nb); %bus data old version
buses=bus(:,1);%making a column matrix with bus numbers
type=bus(:,2);% column matrix for type of bus
Pd=bus(:,3);% column matrix for real power demand of matrix
Qd=bus(:,4);%column matrix for reactive power demand of matrix
Pg=bus(:,5);%column matrix for real power gen of bus
Qg=bus(:,6);%column matrix for reactive power gen of bus
V=bus(:,7);
del=bus(:,8);

nbus=max(buses);%number of buses calculation


P=Pg-Pd;%difference between generation and demand

Q=Qg-Qd;%difference between generation and demand


Pspec=P;% P specidied
Qspec=Q;% Q specified
Y=YBUS(nb); %Ybus is generated
G=real(Y);% real and imaginary part of Y bus separated for calculation
B=imag(Y);

Ym=abs(Y);
theta=angle(Y)
pv=find(type==2 | type==1);
pq=find(type==3);
npv=length(pv);
npq=length(pq);
J=zeros(2*nbus-npq-1);% size of jacobian matrix 2* total no of buses - no pf
pq-1
J1=zeros((nbus-1),(nbus-1));% all 4 sub parts of jacobian matrix HNJL
J2=zeros((nbus-1),(npq));%ll 4 sub parts of jacobian matrix HNJL
J3=zeros((npq),(nbus-1));%ll 4 sub parts of jacobian matrix HNJL
J4=zeros((npq),(npq));%ll 4 sub parts of jacobian matrix HNJL
Pcal=zeros((nbus),1);%matrix for calculated P to calculate eror at the end
Qcal=zeros((npq),1);

for i=2:nbus % Pcal calulation

cal1=0;

for j=1:nbus
if(i~=j)
cal1=cal1+abs(V(i,1))*abs(V(j,1))*Ym(i,j)*cos(del(i,1)-del(j,1)-theta(i,
j));

end
4/3/25 12:37 PM C:\Users\lenovo\Desktop\NRLF.m 2 of 2

end
Pcal(i)=cal1+V(i,1)^2*G(i,i);

end
for i=1:length(npq) % qcal calculation
yv=0;
for j=1:nbus
if(j~=pq(i,1))
yv=yv+(V(pq(i,1),1))*V(j,1)*Ym(pq(i,1),j)*sin(del(pq(i,1),1)-del(j,1)-theta
(pq(i,1),j));
end
end
Qcal(pq(i,1))=-((V(pq(i,1),1)^2)*B(pq(i,1),pq(i,1)))+yv;
end
delp=Pspec-Pcal
delq=Qspec-Qcal
error=max(max(delp(2,:)),max(delq(pq)))
% if error>=epsilon

Pcal
Qcal

end

You might also like