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

PSA Record Programs

This MATLAB program demonstrates the formation of incidence matrices and YBus matrix using different methods. It shows the steps to create element-node incidence matrix, bus incidence matrix and other related matrices. The program also demonstrates YBus formation using singular transformation and direct inception transformation methods. It further shows the ZBus formation using ZBus building algorithm and Kron's reduction method. The program provides the necessary code and output at each step of matrix formation.

Uploaded by

Pravalika Reddy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

PSA Record Programs

This MATLAB program demonstrates the formation of incidence matrices and YBus matrix using different methods. It shows the steps to create element-node incidence matrix, bus incidence matrix and other related matrices. The program also demonstrates YBus formation using singular transformation and direct inception transformation methods. It further shows the ZBus formation using ZBus building algorithm and Kron's reduction method. The program provides the necessary code and output at each step of matrix formation.

Uploaded by

Pravalika Reddy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

MATLAB Program for Formation of Incidence Matrices

Program:-
clc;
clear all;
linedata=[ 1 2 1
213
341
432
5 3 4];
e=max(linedata(:,1));
disp('no of elements');
disp(e);
n=max(max(linedata(:,2)),(max(linedata(:,3))));
disp('no of nodes');
disp(n);
disp('no of branches');
b=n-1;
disp(b);
l=e-b;
disp('no of links');
disp(l);
A1=zeros(e,n);
for i=1:e
A1(i,linedata(i,2))=1;
A1(i,linedata(i,3))=-1;
end
disp('element-node incidence matrix(A1)');
disp(A1);
A1(:,1)=[];
A=A1;
disp('bus incidence matrix A');
disp(A);
Ab=A(1:b,:);
Al=A(n:e,:);
Kt=inv(Ab);
K=(Kt');
disp('branch path incidence matrix K');
disp(K);
Bl=Al*Kt;
B=eye(b,b);
for i=1:b
for j=1:l
B(b+j,i)=Bl(j,i);
end
end
for i=1:l;
B(b+j,:)=Bl(i,:);
end
disp('cutset incidence matrix B');
disp(B);
Cb=-transpose(Bl);
Ccap=eye(e,e);
for i=1:b;
for j=1:l;
Ccap(i,b+j)=Cb(i,j);
end
end
for i=1:l;
C(:,i)=Ccap(:,b+i);
end
disp('loop incidence matrix C');
disp(C);

Output:-

no of elements
5

no of nodes
4

no of branches
3

no of links
2

element-node incidence matrix(A1)


-1 1 0 0
1 0 -1 0
-1 0 0 1
0 -1 1 0
0 0 1 -1

bus incidence matrix A


1 0 0
0 -1 0
0 0 1
-1 1 0
0 1 -1

branch path incidence matrix K


1 0 0
0 -1 0
0 0 1

cutset incidence matrix B


1 0 0
0 1 0
0 0 1
-1 -1 0
0 -1 -1

loop incidence matrix C


1 0
1 1
0 1
1 0
0 1
MATLAB Program YBus Formation Using Singular Transformation Method

Program:-
clc;
clear all;
linedata=[1 1 2 0.2i
2 2 3 0.4i
3 3 4 0.25i
4 1 4 0.2i
5 2 5 0.4i
6 5 4 0.25i];
e=max(linedata(:,1));
n=max(max(linedata(:,2)),(max(linedata(:,3))));
A1=zeros(e,n);
for i=1:e
A1(i,linedata(i,2))=1;
A1(i,linedata(i,3))=-1;
end
A1(:,1)=[];
A=A1;
disp('A');
disp(A);
At=A';
disp('At');
disp(At);
z=linedata(:,4);
z=diag(z)
y=inv(z);
disp('y');
disp(y);
Ybus=At*y*A;
disp('Resulted Ybus')
disp(Ybus);
Output:-
A
-1 0 0 0
1 -1 0 0
0 1 -1 0
0 0 -1 0
1 0 0 -1
0 0 -1 1

At
-1 1 0 0 1 0
0 -1 1 0 0 0
0 0 -1 -1 0 -1
0 0 0 0 -1 1

z=

0.0000 + 0.2000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i
0.0000 + 0.0000i 0.0000 + 0.4000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i
0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.2500i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i
0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.2000i 0.0000 + 0.0000i 0.0000 + 0.0000i
0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.4000i 0.0000 + 0.0000i
0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.2500i

y
0.0000 - 5.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i
0.0000 + 0.0000i 0.0000 - 2.5000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i
0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 - 4.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i
0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 - 5.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i
0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 - 2.5000i 0.0000 + 0.0000i
0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 - 4.0000i

Resulted Ybus
0.0000 -10.0000i 0.0000 + 2.5000i 0.0000 + 0.0000i 0.0000 + 2.5000i
0.0000 + 2.5000i 0.0000 - 6.5000i 0.0000 + 4.0000i 0.0000 + 0.0000i
0.0000 + 0.0000i 0.0000 + 4.0000i 0.0000 -13.0000i 0.0000 + 4.0000i
0.0000 + 2.5000i 0.0000 + 0.0000i 0.0000 + 4.0000i 0.0000 - 6.5000i
MATLAB Program YBus Formation Using Direct Inception Transformation Method

Program:-
clc;
clear all;
close all;
linedata=[1 1 2 0.05 0.15
2 1 3 0.10 0.30
3 2 3 0.15 0.45
4 2 4 0.10 0.30
5 3 4 0.05 0.15];
e=max(linedata(:,1));
n=max(max(linedata(:,2)),(max(linedata(:,3))));
b=n-1;
l=e-b;
j=sqrt(-1);
for k=1:e
se(k)=linedata(k,2);
re(k)=linedata(k,3);
r(k)=linedata(k,4);
x(k)=linedata(k,5);
z(k)=r(k)+j*x(k)
y(k)=inv(z(k))
end
ybus=zeros(n,n);
for k=1:e
p=se(k);
q=re(k);
ybus(p,p)=ybus(p,p)+y(k);
ybus(q,q)=ybus(q,q)+y(k);
ybus(p,q)=-y(k);
ybus(q,p)=ybus(p,q);
end
disp('ybus');
disp(ybus);
Output:-

ybus
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
MATLAB Program ZBus Formation Using ZBus Building Algorithm Method

Program:-
clc;
clear all;
% Add branch 1 from reference to bus1
s=1; %matrix size
z=input('enter the impedence value z01 ==');
z1=z
% Add branch 2 between buses 1 to 2
s=2;%matrix size
z12=input('enter the impedence value z12 ==');
z(s,s)=z(s-1,s-1)+z12;
for i=1:(s-1);
z(s-i,s)=z(s-i,s-1);
z(s,s-i)=z(s-1,s-i);
end;
z2=z
% From branch 3 from buses 2 to 3
s=3;%matrix size
z23=input('enter the impedence value z23 ==');
z(s,s)=z(s-1,s-1)+z23;
for i=1:(s-1);
z(s-i,s)=z(s-i,s-1);
z(s,s-i)=z(s-1,s-i);
end;
z3=z
% From branch 4 from buses 3 to reference
s=4;%matrix size
z30=input('enter the impedence value z30 ==');
z(s,s)=z(s-1,s-1)+z30;
for i=1:(s-1);
z(s-i,s)=z(s-i,s-1);
z(s,s-i)=z(s-1,s-i);
end;
z4=z
% Kron's Reduction
remove=input('enter which row/column to remove ==');
for jj=1:remove;
if jj ~= remove;
j=jj;
if jj >= remove;
j=jj-1;
end
for kk=1:remove;
if kk ~= remove;
k=kk;
if kk >= remove;
k=kk -1;
end;
znew(j,k)=z(jj,kk)-z(jj,remove)*z(remove,kk)/z(remove,remove);
end;
end;
end;
end;
z=znew
Output:-

enter the impedence value z01 ==0.2i

z1 =

0.0000 + 0.2000i

enter the impedence value z12 ==0.3i

z2 =

0.0000 + 0.2000i 0.0000 + 0.2000i


0.0000 + 0.2000i 0.0000 + 0.5000i

enter the impedence value z23 ==0.4i

z3 =

0.0000 + 0.2000i 0.0000 + 0.2000i 0.0000 + 0.2000i


0.0000 + 0.2000i 0.0000 + 0.5000i 0.0000 + 0.5000i
0.0000 + 0.2000i 0.0000 + 0.5000i 0.0000 + 0.9000i

enter the impedence value z30 ==0.1i

z4 =

0.0000 + 0.2000i 0.0000 + 0.2000i 0.0000 + 0.2000i 0.0000 + 0.2000i


0.0000 + 0.2000i 0.0000 + 0.5000i 0.0000 + 0.5000i 0.0000 + 0.5000i
0.0000 + 0.2000i 0.0000 + 0.5000i 0.0000 + 0.9000i 0.0000 + 0.9000i
0.0000 + 0.2000i 0.0000 + 0.5000i 0.0000 + 0.9000i 0.0000 + 1.0000i

enter which row/column to remove ==4

z=

0.0000 + 0.1600i 0.0000 + 0.1000i 0.0000 + 0.0200i


0.0000 + 0.1000i 0.0000 + 0.2500i 0.0000 + 0.0500i
0.0000 + 0.0200i 0.0000 + 0.0500i 0.0000 + 0.0900i
MATLAB Program for Load Flow Analysis Using Guass Siedel method

Program:-
clc;
clear all;
%linedata: se re z
linedata=[1 2 0.02+0.04i
1 3 0.01+0.03i
2 3 0.0125+0.025i];
%busdata: busno. v=Vmag+iVangle Sg=Pg+jQg Sl=Pl+jQl
busdata=[1 1.05+0i 0 0
2 1+0i 0 256.6+110.2i
3 1+0i 0 138.6+45.5i];
nb=length(busdata(:,1));
nl=length(linedata(:,1));
bmva=100;
itermax=7;%---Enter desired number of iterations---%
se=linedata(:,1);
re=linedata(:,2);
z=linedata(:,3);
y=1./z;
ybus=zeros(nb);
for k=1:nl
p=se(k);
q=re(k);
ybus(p,p)=ybus(p,p)+y(k);
ybus(q,q)=ybus(q,q)+y(k);
ybus(p,q)=-y(k);
ybus(q,p)=ybus(p,q);
end
ybus
busno=busdata(:,1);
v=busdata(:,2);
vint=v;
sg=busdata(:,3)/bmva;
sl=busdata(:,4)/bmva;
si=sg-sl;
for kk=1:itermax
iteration=kk
for i=1:nb-1
k=i+1;
sum=0;
for j=1:nb
if j~=k;
sum=sum+ybus(k,j)*v(j);
end
end
v(k)=[conj(si(k))/conj(v(k))-sum]/ybus(k,k);
end
v
end
I12=ybus(1,2)*(v(1)-v(2)); I21=-I12;
I13=ybus(1,3)*(v(1)-v(3)); I31=-I13;
I23=ybus(2,3)*(v(2)-v(3)); I32=-I23;
S12=v(1)*conj(I12); S21=v(2)*conj(I21);
S13=v(1)*conj(I13); S31=v(3)*conj(I31);
S23=v(2)*conj(I23); S32=v(3)*conj(I32);
loss12=(S12+S21)*100;
loss13=(S13+S31)*100;
loss23=(S23+S32)*100;
disp('loss12');
disp(loss12);
disp('loss13');
disp(loss13);
disp('loss23');
disp(loss23);

Output:-

ybus =

20.0000 -50.0000i -10.0000 +20.0000i -10.0000 +30.0000i


-10.0000 +20.0000i 26.0000 -52.0000i -16.0000 +32.0000i
-10.0000 +30.0000i -16.0000 +32.0000i 26.0000 -62.0000i

iteration =1
v=
1.0500 + 0.0000i
0.9825 - 0.0310i
1.0011 - 0.0352i

iteration =2
v=
1.0500 + 0.0000i
0.9816 - 0.0520i
1.0008 - 0.0459i

iteration =3
v=
1.0500 + 0.0000i
0.9808 - 0.0578i
1.0004 - 0.0488i

iteration = 4
v=
1.0500 + 0.0000i
0.9803 - 0.0593i
1.0001 - 0.0496i

iteration =5
v=
1.0500 + 0.0000i
0.9801 - 0.0598i
1.0000 - 0.0499i
iteration = 6
v=
1.0500 + 0.0000i
0.9800 - 0.0599i
1.0000 - 0.0499i

iteration =7
v=
1.0500 + 0.0000i
0.9800 - 0.0600i
1.0000 - 0.0500i

loss12
-8.4983 -16.9965i

loss13
-5.0015 -15.0044i

loss23
-0.7979 - 1.5958i
MATLAB Program for Load Flow Analysis Using NRLF method

Program:-
clc;
clear all;
%ybusdata
Y11=20;
Y12=20;
Y21=20;
Y22=20;
t11=-90*pi/180;
t12=90*pi/180;
t22=-90*pi/180;
t21=90*pi/180;
% t21=t12;
% t22=t11;
p2s=-1;
q2s=-0.5;
v1=1;
del1=0;
v2=1;
del2=0;
for i=1:4
p2cal=(v2*v1*Y21*cos(t21+del1-del2))+(v2*v2*Y22*cos(t22+del2-del2));
q2cal=-((v2*v1*Y21*sin(t21+del1-del2))+(v2*v2*Y22*sin(t22+del2-del2)));
j1=v2*v1*Y21*sin(t21+del1-del2);
j2=v1*Y21*cos(t21+del1-del2);
j3=v2*v1*Y21*cos(t21+del1-del2);
j4=-(v1*Y21*sin(t21+del1-del2)+2*v2*Y22*sin(t22));
j=[ j1 j2;j3 j4]; %j is the jacobian matrix
dp=p2s-p2cal;
dq=q2s-q2cal;
dpdq=[dp;dq]; %dpdq is the power mismatch vector
ddv=inv(j)*dpdq; %ddv is the correction vector
%updation of angle & voltage magnitude
del2=del2+ddv(1)
v2=v2+ddv(2)
end
Output:-

del2 =

-0.0500

v2 =

0.9750

del2 =

-0.0514

v2 =

0.9730

del2 =

-0.0514

v2 =

0.9730

del2 =

-0.0514

v2 =

0.9730
MATLAB Program for Load Flow Analysis Using DCLF method

Program:-
clc;
clear all;
%ybusdata
Y11=20;
Y12=20;
Y21=20;
Y22=20;
t11=-90*pi/180;
t12=90*pi/180;
t22=-90*pi/180;
t21=90*pi/180;
% t21=t12;
% t22=t11;
p2s=-1;
q2s=-0.5;
v1=1;
del1=0;
v2=1;
del2=0;
for i=1:4
p2cal=(v2*v1*Y21*cos(t21+del1-del2))+(v2*v2*Y22*cos(t22+del2-del2));
q2cal=-((v2*v1*Y21*sin(t21+del1-del2))+(v2*v2*Y22*sin(t22+del2-del2)));
j1=v2*v1*Y21*sin(t21+del1-del2);
j2=0;
j3=0;
j4=-(v1*Y21*sin(t21+del1-del2)+2*v2*Y22*sin(t22));
j=[ j1 j2;j3 j4]; %j is the jacobian matrix
dp=p2s-p2cal;
dq=q2s-q2cal;
dpdq=[dp;dq]; %dpdq is the power mismatch vector
ddv=inv(j)*dpdq; %ddv is the correction vector
%updation of angle & voltage magnitude
del2=del2+ddv(1)
v2=v2+ddv(2)
end
Output:-

del2 =

-0.0500

v2 =

0.9750

del2 =

-0.0513

v2 =

0.9731

del2 =

-0.0514

v2 =

0.9730

del2 =

-0.0514

v2 =

0.9730
MATLAB Program for Load Flow Analysis Using FDCLF method
Program:-

clc
clear all
basemva=100;
% Sno From To R X Y/2
linedata=[1 1 2 0 0.1 0.01
2 1 3 0 0.1 0.01
3 2 3 0 0.1 0.01];
e = max(linedata(:,1));
% n code v del pg qg pd qd qmin qmax qsh
busdata=[1 0 1.06 0 0 0 0 0 0 0 0
2 2 1.00 0 40 30 20 10 0 0 0
3 2 1.00 0 0 0 45 15 0 0 0 ];
% Bus Type Slack =1, PV = 2, PQ = 3
n=max(max(linedata(:,2)),(max(linedata(:,3))));
j==sqrt(-1);
for k=1:e
se(k)=linedata(k,2);
re(k)=linedata(k,3);
r(k)=linedata(k,4);
x(k)=linedata(k,5);
z(k)=r(k)+j*x(k);
y(k)=inv(z(k));
end
ybus=zeros(n,n);
for k=1:e
p=se(k);
q=re(k);
ybus(p,p)=ybus(p,p)+y(k);
ybus(q,q)=ybus(q,q)+y(k);
ybus(p,q)=-y(k);
ybus(q,p)=ybus(p,q);
end
nbus=length(busdata(:,2));
for n=1:nbus
bus(n)=busdata(n,1);
kb(n)=busdata(n,2);
vm(n)=busdata(n,3);
delta(n)=busdata(n,4);
pg(n)=busdata(n,5);
qg(n)=busdata(n,6);
pd(n)=busdata(n,7);
qd(n)=busdata(n,8);
qmin(n)=busdata(n,9);
qmax(n)=busdata(n,10);
qsh(n)=busdata(n,11);
delta(n)=pi/180*delta(n);
v(n)=vm(n)*cos(delta(n))+j*vm(n)*sin(delta(n));
p(n)=(pg(n)-pd(n))/basemva;
q(n)=(qg(n)-qd(n))/basemva;
s(n)=p(n)+j*q(n);
end
ym=abs(ybus);
t=angle(ybus);
nline=length(linedata(:,1));
ii=0;
for n=1:nbus
if(kb(n)==1|kb(n)==2)
ii=ii+1;
jj=0;
for m=1:nbus
if(kb(m)==1|kb(m)==2)
jj=jj+1;
B1(ii,jj)=imag(ybus(n,m));
end
end
end
end
ii=0;
for n=1:nbus
if(kb(n)==2)
ii=ii+1;
jj=0;
for m=1:nbus
if(kb(m)==2)
jj=jj+1;
B2(ii,jj)=imag(ybus(n,m));
end
end
end
end
B1inv=inv(B1);
B2inv=inv(B2);
maxerror=0.1;
iter=0;
while maxerror>0.00001&iter<15
iter=iter+1;
id=0;
iv=0;
for n=1:nbus
J11=0;
J33=0;
for m=1:nline
if(p(m)==n|q(m)==n)
if(p(m)==n)
l=q(m);
end
if(q(m)==n)
l=p(m);
end
J11=J11+vm(n)*vm(l)*ym(n,l)*sin(t(n,l)-delta(n)+delta(l));
J33=J33+vm(n)*vm(l)*ym(n,l)*cos(t(n,l)-delta(n)+delta(l));
end
end
pk=vm(n)^2*ym(n,n)*cos(t(n,n))+J33;
qk=-vm(n)^2*ym(n,n)*sin(t(n,n))-J11;
if(kb(n)==0)
p(n)=pk;
q(n)=qk;
end
if(kb(n)==1)
q(n)=qk;
qgc=q(n)*basemva+qd(n)-qsh(n);
if qmax(n)~=0
if iter<=20
if iter>=10
if(qgc<qmin(n)|qgc>qmax(n))
if(qgc<qmin(n))
vm(n)=vm(n)+0.0005;
else
vm(n)=vm(n)-0.0005;
end
end
end
end
end
end
if(kb(n)~=0)
id=id+1;
dp(id)=p(n)-pk;
dpv(id)=(p(n)-pk)/vm(n);
iv=iv+1;
dq(iv)=q(n)-qk;
dqv(iv)=(q(n)-qk)/vm(n);
end
end
f=dpv';
dd=-B1inv*dpv';
dv=-B2inv*dqv';
id=0;
iv=0;
for n=1:nbus
if(kb(n)~=0)
id=id+1;
delta(n)=delta(n)+dd(id);
iv=iv+1;
vm(n)=vm(n)+dv(iv);
end
end
maxerror=max(max(abs(dp)),max(abs(dq)));
iter
E=vm.*cos(delta)+j*vm.*sin(delta)
end
Output:-

iter = 1
E =1.0600 + 0.0000i -0.9917 + 0.0017i -1.0031 + 0.0234i

iter =2
E =1.0600 + 0.0000i 0.9910 - 0.0002i 0.9988 - 0.0002i

iter = 3
E =1.0600 + 0.0000i -0.9877 + 0.0017i -0.9966 + 0.0234i

iter = 4
E = 1.0600 + 0.0000i 0.9853 - 0.0002i 0.9941 - 0.0001i

iter = 5
E = 1.0600 + 0.0000i -0.9827 + 0.0017i -0.9913 + 0.0233i

iter = 6
E = 1.0600 + 0.0000i 0.9801 - 0.0002i 0.9889 - 0.0001i

iter = 7
E = 1. 0600 + 0.0000i -0.9774 + 0.0017i -0.9860 + 0.0233i

iter = 8
E = 1.0600 + 0.0000i 0.9748 - 0.0002i 0.9837 + 0.0000i

iter = 9
E = 1.0600 + 0.0000i -0.9721 + 0.0017i -0.9808 + 0.0232i

iter = 10
E = 1.0600 + 0.0000i 0.9695 - 0.0002i 0.9785 + 0.0001i

iter = 11
E = 1.0600 + 0.0000i -0.9668 + 0.0017i -0.9755 + 0.0231i

iter =12
E =1.0600 + 0.0000i 0.9642 - 0.0002i 0.9732 + 0.0001i

iter =13
E =1.0600 + 0.0000i -0.9615 + 0.0017i -0.9702 + 0.0231i

iter =14
E =1.0600 + 0.0000i 0.9588 - 0.0002i 0.9679 + 0.0002i

iter = 15
E =1.0600 + 0.0000i -0.9561 + 0.0017i -0.9649 + 0.0230i
MATLAB Program for GOSF
Program:-
clc;
clear all;
% Line Data: SE RE R X
linedata=[1 2 0 0.2000
1 4 0 0.2500
2 3 0 0.1500
2 4 0 0.3000
3 4 0 0.4000];
nb=max(max(linedata(:,1)),max(linedata(:,2)));
nl=length(linedata(:,1));
se=linedata(:,1);
re=linedata(:,2);
r=linedata(:,3);
x=linedata(:,4);
z=complex(r,x);
y=1./z;
ybus=zeros(nb);
for k= 1:nl
p = se(k); q = re(k);
ybus(p,p) = ybus(p,p)+ y(k);
ybus(q,q) = ybus(q,q)+ y(k);
ybus(p,q) = -y(k);
ybus(q,p) = ybus(p,q);
end
By=-imag(ybus);
By1=By(2:end,2:end);
X2=inv(By1);
X1=zeros(nb);
X1(2:end,2:end)=X1(2:end,2:end)+X2
genk=input('Enter the bus k on outage other than slack bus : \n ');
for i=1:nl
a(i)=0;
a(i)=(1/linedata(i,4))*(X1(linedata(i,1),genk)-(X1(linedata(i,2),genk)));
end
disp(' Generation outage sensitivity Factor ');
disp(a)
OUTPUT:-
Enter the bus k on outage other than slack bus :
2
Generation outage sensitivity Factor
-0.6895 -0.3105 0.1096 0.2009 0.1096

Enter the bus k on outage other than slack bus :


3
Generation outage sensitivity Factor
-0.6073 -0.3927 -0.6849 0.0776 0.3151

Enter the bus k on outage other than slack bus :


4
Generation outage sensitivity Factor
-0.3881 -0.6119 -0.1370 -0.2511 -0.1370
MATLAB Program for LOSF

Program:-
clc;
clear all;
% Line Data: SE RE R X
linedata=[1 2 0 0.2000
1 4 0 0.2500
2 3 0 0.1500
2 4 0 0.3000
3 4 0 0.4000];
nb=max(max(linedata(:,1)),max(linedata(:,2)));
nl=length(linedata(:,1));
se=linedata(:,1);
re=linedata(:,2);
r=linedata(:,3);
x=linedata(:,4);
z=complex(r,x);
y=1./z;
ybus=zeros(nb);
for k=1:nl
p = se(k);
q = re(k);
ybus(p,p) = ybus(p,p)+ y(k);
ybus(q,q) = ybus(q,q)+ y(k);
ybus(p,q) = -y(k);
ybus(q,p) = ybus(p,q);
end
By=-imag(ybus);
By1=By(2:end,2:end);
X2=inv(By1);
X1=zeros(nb);
X1(2:end,2:end)=X1(2:end,2:end)+X2;
mnn=input('Enter the outage line number (mn) position ');
for i=1:nl
b(i)=0;
n1=(X1(se(i),re(mnn)))-(X1(se(i),se(mnn)));
n2=(X1(re(i),re(mnn)))-(X1(re(i),se(mnn)));
d1=X1(se(mnn),se(mnn))+X1(re(mnn),re(mnn))-2*(X1(se(mnn),re(mnn)));
d2=x(mnn);
mf1=x(mnn)/x(i);
b(i)=mf1*(n1-n2)/[d1-d2];
end
disp(' Line Outage Sensitivity factor ');
disp(b)
Output:-

Enter the outage line number (mn) position 1


Line Outage Sensitivity factor
2.2206 1.0000 -0.3529 -0.6471 -0.3529

Enter the outage line number (mn) position 2


Line Outage Sensitivity factor
1.0000 1.5765 0.3529 0.6471 0.3529

Enter the outage line number (mn) position 3


Line Outage Sensitivity factor
-0.4000 0.4000 3.8667 0.6000 -1.0000

Enter the outage line number (mn) position 4


Line Outage Sensitivity factor
-0.5500 0.5500 0.4500 0.8250 0.4500

Enter the outage line number (mn) position 5


Line Outage Sensitivity factor
-0.4000 0.4000 -1.0000 0.6000 0.8250
MATLAB Program for Fault Analysis of LG fault
Program:-

clc;
clear all;
disp('Title: To Obtain Fault current IpF, Sequence Components of voltages at all buses for a Single Line
to Ground Fault at bus p');
Zbus0=input('Enter Zbus0 matrix:\n');
Zbus1=input('Enter Zbus1 matrix:\n');
k=length(Zbus0);
p=input('Enter the node at which fault occurs:');
Zf=input('\n enter fault impedance Zf:');
disp('Line to ground(L-G) fault calculations');
IpF=(1/(Zbus0(p,p)+2*Zbus1(p,p)+3*Zf))*[1 1 1]';
fprintf('\n fault current I %d(F)=',p);
disp(IpF);
disp('Zero, Positive and Negative sequence components of voltages are:');
for i=1:k
EiF=[0 1 0]-(1/(Zbus0(p,p)+2*Zbus1(p,p)+3*Zf))*[Zbus0(i,p) Zbus1(i,p) Zbus1(i,p)];
fprintf('E%d(F)=',i);
disp(EiF)
end
Output:-

Enter Zbus0 matrix:


[0.085714 0 0 0;
0 0.35 0.1 0;
0 0.1 0.1 0;
0 0 0 2.498];

Enter Zbus1 matrix:


[0.272 0.144 0.112 0.08;
0.144 0.288 0.224 0.16;
0.112 0.224 0.252 0.18;
0.08 0.16 0.18 0.12];

Enter the node at which fault occurs:3

enter fault impedance Zf:1

Line to ground(L-G) fault calculations

fault current I 3(F)=


0.2775
0.2775
0.2775

Zero, Positive and Negative sequence components of voltages are:


E1(F)= 0 0.9689 -0.0311

E2(F)= -0.0277 0.9378 -0.0622

E3(F)= -0.0277 0.9301 -0.0699

E4(F)= 0 0.9501 -0.0499


MATLAB Program for Fault Analysis of LLLG fault
Program:-

clc;
clear all;
disp('Title: Obtain Fault Current IpF and Voltages at all buses for a 3-Phase Fault at bus p');
% Zbus=input('Enter Zbus1 matrix:\n');
Zbus= [0.14074i 0.11111i 0.08889i 0.05926i;
0.11111i 0.16667i 0.13333i 0.08889i;
0.08889i 0.13333i 0.16667i 0.11111i;
0.05926i 0.08889i 0.11111i 0.14074i];
k=length(Zbus);
p=input('Enter the node at which fault occurs:');
Zf=input('\n enter fault impedance Zf:');
disp('LLLG fault calculations');
IpF=(1/(Zbus(p,p)+Zf));
fprintf('\n fault current I %d(F)=',p);
disp(IpF);
disp('Voltages at all buses:');
for i=1:k
EiF=1-(IpF*Zbus(i,p));
fprintf('E%d(F)=',i);
disp(EiF);
End
Output:

Title: Obtain Fault Current IpF and Voltages at all buses for a 3-Phase Fault at bus p
Enter the node at which fault occurs:2

enter fault impedance Zf:1


LLLG fault calculations

fault current I 2(F)= 0.9730 - 0.1622i

Voltages at all buses:


E1(F)= 0.9820 - 0.1081i

E2(F)= 0.9730 - 0.1622i

E3(F)= 0.9784 - 0.1297i

E4(F)= 0.9856 - 0.0865i


MATLAB Program for PV Curve

Program:-
clear all;
clc;
phi=input('enter phi:');
phi=phi*(pi/180);
pf=cos(phi);
k=tan(phi);
disp(pf);
disp(k);
pint=0;
for i=1:100000;
p(i)=pint+i*0.00001;
q=p(i)*k;
vb(i)=0.25-p(i)*p(i)-q;
va(i)=0.5-q;
if vb(i)<0
break
end
vc(i)=sqrt(vb(i));
v1(i)=va(i)+vc(i);
if v1(i)<0
break
end
v11(i)=sqrt(v1(i));
pr1(i)=p(i);
v2(i)=va(i)-vc(i);
if v2(i)<0
break
end
v22(i)=sqrt(v2(i));
pr2(i)=p(i);
end
plot(pr1,v11,pr2,v22)
hold on;
grid on
Output:-

enter phi:25
0.9063

0.4663

enter phi:35
0.8192

0.7002
MATLAB Program for QV Curve
Program:-
clear all;
clc;
p=0.4;
x=input('enter x angle:');
for i=1:7400
y=i*0.01-x;
phi=y*pi/180;
pf=cos(phi);
t(i)=tan(phi);
q=p*t(i);
Va(i)=(0.5-q);
Vb(i)=0.25-p*p-q;
if Vb(i)<0
break
end
Vc(i)=sqrt(Vb(i));
V1(i)=Va(i)+Vc(i);
if V1(i)<0
break
end
pr1(i)=p;
qr1(i)=q;
Vs(i)=sqrt(V1(i));
V2(i)=Va(i)-Vc(i);
if V2(i)<0
break
end
Vr(i)=sqrt(V2(i));
pr2(i)=p;
qr2(i)=q;
end
qr1;
Vs;
qr2;
Vr;
plot(Vs,-qr1);
hold on;
plot(Vr,-qr2);
grid on
Output:-

enter x angle:35

You might also like