0% found this document useful (0 votes)
3 views17 pages

Kalyan Ps

The document contains MATLAB code for calculating the bus admittance matrix (Ybus) and the impedance matrix (Zbus) for a power system network. It includes data for multiple buses and lines, and iteratively computes voltage and power values while considering various constraints. The output displays the Ybus, Zbus, and voltage results after several iterations.

Uploaded by

Kalyan Ram
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)
3 views17 pages

Kalyan Ps

The document contains MATLAB code for calculating the bus admittance matrix (Ybus) and the impedance matrix (Zbus) for a power system network. It includes data for multiple buses and lines, and iteratively computes voltage and power values while considering various constraints. The output displays the Ybus, Zbus, and voltage results after several iterations.

Uploaded by

Kalyan Ram
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/ 17

22011A0205

clc;
close all;
baseMVA=100;
linedata=[1 2 0.02 0.06 0.03 1;
1 3 0.08 0.24 0.025 1;
2 3 0.06 0.18 0.02 1;
2 4 0.06 0.18 0.02 1;
3 4 0.01 0.03 0.01 1;
4 5 0.08 0.24 0.025 1 ];
lp=linedata(:,1);
lq=linedata(:,2);
r=linedata(:,3);
x=linedata(:,4);
ycp=linedata(:,5);
a=linedata(:,6);
y=1 ./(r+1i .* x);
ycp=1i.*ycp;
nbus=max(max(lp),max(lq));
nline=length(lp);
p=zeros(nbus,nbus);
for k=1:nline
p(lp(k),lq(k))=(p(lp(k),lq(k)))-(y(k)/a(k));
p(lp(k),lq(k))=p(lp(k),lq(k));
end
for m=1:nbus
22011A0205

for n=1:nline
if lp(n)==m
p(m,m)=p(m,m)+(y(n)/(a(n)^2))+ycp(n);
elseif lq(n)==m
p(m,m)=p(m,m)+y(n)+ycp(n);
end
end
end
disp('BUS ADMITTANCE MATRIX(Ybus):');
disp(p);
22011A0205

Output:
BUS ADMITTANCE MATRIX(Ybus):
6.2500 -18.6950i -5.0000 +15.0000i -1.2500 + 3.7500i 0.0000 + 0.0000i 0.0000 +
0.0000i
0.0000 + 0.0000i 8.3333 -24.9300i -1.6667 + 5.0000i -1.6667 + 5.0000i 0.0000 +
0.0000i
0.0000 + 0.0000i 0.0000 + 0.0000i 12.9167 -38.6950i -10.0000 +30.0000i 0.0000
+ 0.0000i
0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 12.9167 -38.6950i -1.2500 +
3.7500i
0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 1.2500 -
3.7250i
22011A0205
clc;
linedata = [1 1 0 1i*0.05;
2 2 1 1i*0.1;
3 3 2 1i*0.2;]
[elements,columns]=size(linedata);
zbus = [];
currentbus = 0;
for count=1:elements
[rows,cols] = size(zbus);
= linedata(count,2);
tb = linedata(count,3);
zs = linedata(count,4);
newbus=max( ,tb);
ref = min( ,tb);
if newbus>currentbus && ref==0
fprin ('new bus to ref');
zbus = [zbus zeros(rows,1) zeros(1,cols) zs]
currentbus = newbus;
con nue
end
if newbus>currentbus && ref~=0
fprin ('new bus to old');
zbus=[zbus zbus(:,ref); zbus(ref,:) zs+zbus(ref,ref)]
currentbus=newbus;
con nue
end
22011A0205

if newbus<=currentbus && ref==0


fprin ('oldbus to ref');
zbus=zbus;
1./(zbus(newbus,newbus)+zs)*zbus(:,newbus)*zbus(newbus,:);
con nue
end
if newbus<=currentbus && ref~=0
fprin ('oldbus to old');
zbus=zbus-1./(zs+zbus( , )+zbus(tb,tb)-2*zbus( ,tb))*((zbus(:, )-
zbus(:,tb))*((zbus( ,:)-zbus(tb,:))));
con nue
end
end
zbus;
22011A0205

Output:
linedata =

1.0000 + 0.0000i 1.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0500i


2.0000 + 0.0000i 2.0000 + 0.0000i 1.0000 + 0.0000i 0.0000 + 0.1000i
3.0000 + 0.0000i 3.0000 + 0.0000i 2.0000 + 0.0000i 0.0000 + 0.2000i

new bus to ref


zbus =

0.0000 + 0.0500i

new bus to old


zbus =

0.0000 + 0.0500i 0.0000 + 0.0500i


0.0000 + 0.0500i 0.0000 + 0.1500i

new bus to old


zbus =

0.0000 + 0.0500i 0.0000 + 0.0500i 0.0000 + 0.0500i


0.0000 + 0.0500i 0.0000 + 0.1500i 0.0000 + 0.1500i
0.0000 + 0.0500i 0.0000 + 0.1500i 0.0000 + 0.3500i
22011A0205

clc;
close all;
clear ;
linedata=[1 2 0.05 0.15 0 1;
1 3 0.10 0.30 0 1 ;
2 3 0.15 0.45 0 1 ;
2 4 0.10 0.30 0 1;
3 4 0.05 0.15 0 1;]
=linedata(:,1);
tb=linedata(:,2);
r=linedata(:,3);
x=linedata(:,4);
ycp=linedata(:,5);
a=linedata(:,6);
z=r+1.i*x;
y=1./z;
ycp=1.i*ycp;
nb=max(max( ),max(tb));
n1=length( );
Y=zeros(nb,nb);
for k=1:n1
Y( (k),tb(k))=Y( (k),tb(k))-y(k)/a(k);
Y(tb(k), (k))=Y( (k),tb(k));
end
22011A0205

for m=1:nb
for n=1:n1
if (n)==m
Y(m,m)=Y(m,m)+y(n)/(a(n)^2)+ycp(n);
else
if tb(n)==m
Y(m,m)=Y(m,m)+y(n)+ycp(n);
end
end
end
end
Y
busdata=[1 1 1.04 0 0 0 0 0 0 0;
2 2 1.04 0 0.5 0 0 0 0.2 1.0 ;
3 3 1.0 0 0 0 1.0 -0.5 0 0 ;
4 4 1.0 0 0 0 -0.3 0.1 0 0 ;]
Y=Y();
bus=busdata(:,1);
type=busdata(:,2);
v=busdata(:,3);
th=busdata(:,4);
genMW=busdata(:,5);
genMVAR=busdata(:,6);
loadMW=busdata(:,7);
loadMVAR=busdata(:,8);
22011A0205
Qmin=busdata(:,9);
Qmax=busdata(:,10);
nbus=max(bus);
p=genMW-loadMVAR;
Q=genMVAR-loadMVAR;
vprev=v;
toler=1;
itera on=1;
while (toler>0.01)
for i=2:nbus
sumyv=0;
for k=1:nbus
if i~=k
sumyv=sumyv+(Y(i,k)*v(k));
end
end
if type(i)==2
Q(i)=-imag(conj(v(i))*(sumyv+Y(i,i)*v(i)));
if Q(i)>Qmax(i)||Q(i)<Qmin(i)
if (Q(i)<Qmin(i))
Q(i)=Qmin(i);
else
Q(i)=Qmax(i);
end
type(i)=3;
end
22011A0205

end
v(i)=(1/Y(i,i))*((p(i)-1i*Q(i))/conj(v(i))-sumyv);
if type(i)==2
vmag=abs(vprev(i));
th=angle(v(i));
v(i)=vmag*(cos(th)+1i*sin(th));
end
end
toler=max(abs(abs(v)-abs(vprev)));
vprev=v;
disp("voltage at itera on");
disp(itera on);
disp(v);
itera on=itera on+1;
end
itera on
v
vmag=abs(v)
ang=180/pi*angle(v)
p
Q
22011A0205
OUTPUT:

linedata = 5×6
1.0000 2.0000 0.0500 0.1500 0 1.0000
1.0000 3.0000 0.1000 0.3000 0 1.0000
2.0000 3.0000 0.1500 0.4500 0 1.0000
2.0000 4.0000 0.1000 0.3000 0 1.0000
3.0000 4.0000 0.0500 0.1500 0 1.0000

Y = 4×4 complex
3.0000 - 9.0000i -2.0000 + 6.0000i -1.0000 + 3.0000i 0.0000 + 0.0000i
-2.0000 + 6.0000i 3.6667 -11.0000i -0.6667 + 2.0000i -1.0000 + 3.0000i
-1.0000 + 3.0000i -0.6667 + 2.0000i 3.6667 -11.0000i -2.0000 + 6.0000i
0.0000 + 0.0000i -1.0000 + 3.0000i -2.0000 + 6.0000i 3.0000 - 9.0000i

busdata = 4×10
1.0000 1.0000 1.0400 0 0 0 0 0 0 0
2.0000 2.0000 1.0400 0 0.5000 0 0 0 0.2000 1.0000
3.0000 3.0000 1.0000 0 0 0 1.0000 -0.5000 0 0
4.0000 4.0000 1.0000 0 0 0 -0.3000 0.1000 0 0
22011A0205
voltage at itera on
1
1.0400 + 0.0000i
1.0395 + 0.0335i
1.0726 + 0.0334i
1.0482 + 0.0267i
voltage at itera on
2
1.0400 + 0.0000i
1.0759 + 0.0484i
1.1010 + 0.0504i
1.0801 + 0.0430i
voltage at itera on
3
1.0400 + 0.0000i
1.0884 + 0.0550i
1.1190 + 0.0604i
1.0967 + 0.0520i
voltage at itera on
4
1.0400 + 0.0000i
1.0957 + 0.0591i
1.1283 + 0.0660i
1.1056 + 0.0571i
itera on = 5
v = 4×1 complex
1.0400 + 0.0000i
22011A0205

1.0957 + 0.0591i

1.1283 + 0.0660i

1.1056 + 0.0571i

vmag = 4×1

1.0400

1.0973

1.1303

1.1071

ang = 4×1

3.0849

3.3486

2.9542

p = 4×1

0.5000

0.5000

-0.1000

Q = 4×1

0.2000

0.5000

-0.1000
22011A0205
clc;
nbus=3;
Y=[5.882-23.528i -2.94+11.764i -2.941+11.764i;
-2.941+11.764i 5.882-23.528i -2.941+11.764i;
-2.941+11.764i -2.941+11.764i 5.882-23.528i];
busdata=[1 1 1.04 0 0 0 0 0;
2 2 1.04 0 -1.5 0 0 0;
3 3 1 0 0.5 1 0 0;];
bus=busdata(:,1);
type=busdata(:,2);
V=busdata(:,3);
del=busdata(:,4);
P=busdata(:,5);
Q=busdata(:,6);
Qmin=busdata(:,7);
Qmax=busdata(:,8);
Psp=P;
Qsp=Q;
G=real(Y);
B=imag(Y);
PV=find(type==2|type==1);
PQ=find(type==3);
npv=length(PV);
npq=length(PQ);
tol=1;
iter=1;
22011A0205
while(tol>0.01)
P=zeros(nbus,1);
Q=zeros(nbus,1);
for i=1:nbus
for k=1:nbus
P(i)=P(i)+V(i)*V(k)*(G(i,k)*cos(del(i)-del(k))+B(i,k)*sin(del(i)-del(k)));
Q(i)=Q(i)+V(i)*V(k)*(G(i,k)*sin(del(i)-del(k))-B(i,k)*cos(del(i)-del(k)));
end
end
if iter<=7&&iter>2
for n=2:nbus
if type(n)==2
if Q<Qmin(n)
Q=Qmin(n);
elseif Q>Qmax(n)
Q=Qmax(n);
end
end
end
end
dPa=Psp-P;
dQa=Qsp-Q;
k=1;
dQ=zeros(npq,1);
for i=1:nbus
if type(i)==3
22011A0205
dQ(k,1)=dQa(i);
k=k+1;
end
end
dP=dPa(2:nbus);
M=[dP;dQ];
j1=zeros(nbus-1,nbus-1);
for i=1:(nbus-1)
m=i+1;
for k=1:(nbus-1)
n=k+1;
if n==m
j1(i,k)=-V(m)^2*B(m,m);
else
j1(i,k)=-V(m)*V(n)*B(m,n);
end
end
end
j2=zeros(nbus-1,npq);
j3=zeros(npq,nbus-1);
j4=zeros(npq,npq);
for i=npq
for k=npq
j4(i,k)=j1(nbus-1,nbus-1);
end
end
22011A0205
J=[j1 j2;
j3 j4];
X=(inv(J))*M;
dTh=X(1:nbus-1);
dV=X(nbus:end);
del(2:nbus)=dTh+del(2:nbus);
k=1;
for i=2:nbus
if type(i)==3
V(i)=dV(k)+V(i);
k=k+1;
end
end
tol=max(abs(M));
iter;
V;
del;
J;
iter=iter+1;
end

You might also like