Code Print NRLF
Code Print 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);
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);
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