0% found this document useful (0 votes)
9 views

codedlf

The document contains a MATLAB function named DLF that performs power flow calculations for a given number of buses in a power system. It processes bus data, computes power generation and demand, and iteratively updates voltage and angle values using the Jacobian matrix. The function utilizes the YBUS matrix to calculate power flows and convergence is achieved through iterative adjustments of voltage and phase angles.
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)
9 views

codedlf

The document contains a MATLAB function named DLF that performs power flow calculations for a given number of buses in a power system. It processes bus data, computes power generation and demand, and iteratively updates voltage and angle values using the Jacobian matrix. The function utilizes the YBUS matrix to calculate power flows and convergence is achieved through iterative adjustments of voltage and phase angles.
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/ 3

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

m 1 of 3

function DLF= DLF(nb)


bus = BUSDATA(nb); %bus data function modified
buses=bus(:,1);%making a column matrix with bus numbers
type=bus(:,2);% column matrix for type of bus
V=bus(:,3);% column matrix for voltage of bus
del=zeros(length(V),1);%
Pg=bus(:,5);%column matrix for real power gen of bus
Qg=bus(:,6);%column matrix for reactive power gen of bus
Pl=bus(:,7);%column matrix for real power demand of matrix
Ql=bus(:,8);%column matrix for reactive power demand of matrix
Qmin=bus(:,9);% limits on Q
Qmax=bus(:,10);

nbus=max(buses); %num of buses


P=Pg-Pl;% P given
Q=Qg-Ql;%Q given
Pspec=P;% Pspecified
Qspec=Q;% Q specified
Y=YBUS(nb);% generating ybus

G=real(Y);% real and imaginary part separation in ybus


B=imag(Y);

Ym=abs(Y);% absolute and angle part separation


theta=angle(Y)
pv=find(type==2);
pq=find(type==3);
sl=find(type==1);% slack bus

npv=length(pv); % number of pv bus


npq=length(pq);% number of pq bus

J=zeros(2*nbus-npq-1);% forming jacobian matrix


J1=zeros((nbus-1),(nbus-1));
J2=zeros((nbus-1),(npq));
J3=zeros((npq),(nbus-1));
J4=zeros((npq),(npq));

iteration=1;
Vnew=V;
Delnew=del;
while iteration<=2
iteration=iteration+1;
V=Vnew;
del=Delnew;

Pcal=zeros(nbus,1);
Qcal=zeros(nbus,1);
4/3/25 12:37 PM C:\Users\lenovo\Desktop\DLF.m 2 of 3

for i=1:nbus

for j=1:nbus
if(j~=i)

Pcal(i,1)=Pcal(i,1)+abs(V(i,1))*abs(V(j,1))*Ym(i,j)*cos(del(i,1)-del(j,1)-
theta(i,j));
Qcal(i,1)=Qcal(i,1)+abs(V(i,1))*abs(V(j,1))*Ym(i,j)*sin(del(i,1)-del(j,1)-
theta(i,j));

end
end
Pcal(i,1)=Pcal(i,1)+V(i,1)^2*G(i,i);
Qcal(i,1)=Qcal(i,1)-V(i,1)^2*B(i,i);
end

delp=Pspec-Pcal
delq=Qspec-Qcal
Pcal
Qcal

B1=zeros(nbus-1,nbus-1);
es=[pv;pq];
for i=1:(nbus-1)
m=es(i,1);
for j=1:(nbus-1)
n=es(j,1);
B1(i,j)=-B(m,n);
end
end
B1
B11=zeros(npq,npq);
for i=1:npq
m=pq(i,1);
for j=1:npq
n=pq(j,1);
B11(i,j)=-B(m,n);
end
end
B11

delP=[delp(pv);delp(pq)]
delQ= [delq(pq)]

Ddel= inv(B1)*[delP./[V(pv);V(pq)]]
delV=inv(B11)*delQ
4/3/25 12:37 PM C:\Users\lenovo\Desktop\DLF.m 3 of 3

VV=zeros(nbus,1);
DD=zeros(nbus,1);
VV(pq)=delV;
DD(pv)=Ddel(1:npv);
DD(pq)=Ddel(npv+1:end);
Vnew=V+VV
Delnew=del+DD

end
end

You might also like