100% found this document useful (1 vote)
65 views32 pages

Psa File

The document contains MATLAB code for performing load flow analysis using the Gauss-Seidel method. It includes code to define the bus data, form the bus admittance matrix Y, input load data, initialize voltages, and iterate using Gauss-Seidel to solve for bus voltages until convergence within a specified tolerance is achieved. The code is tested on a 3-bus system and outputs the final converged voltage solutions after 11 iterations.

Uploaded by

Nitin Bhardwaj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
65 views32 pages

Psa File

The document contains MATLAB code for performing load flow analysis using the Gauss-Seidel method. It includes code to define the bus data, form the bus admittance matrix Y, input load data, initialize voltages, and iterate using Gauss-Seidel to solve for bus voltages until convergence within a specified tolerance is achieved. The code is tested on a 3-bus system and outputs the final converged voltage solutions after 11 iterations.

Uploaded by

Nitin Bhardwaj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 32

CODE FOR NR METHOD

clc;
dx=[10;10;10];
x=[1;1;1];
c=[11;3;6];
iter=0;
while max(abs(dx))>=0.0001 & iter<10;
iter=iter+1
f=[x(1)^2-x(2)^2+x(3)^2
x(1)*x(2)+x(2)^2-3*x(3)
x(1)-x(1)*x(3)+x(2)*x(3)];
dc=c-f
J=[2*x(1) -2*x(2) 2*x(3)
x(2) x(1)+2*x(2) -3
1-x(3) x(3) -x(1)+x(2)]

dx=J\dc
x=x+dx

end
OUTPUT
iter =1

dc = 10

J= 2 -2 2

1 3 -3

0 1 0

dx = 4.7500

5.0000

5.2500

x = 5.7500

6.0000

6.2500

iter = 2
dc = -25.1250

-48.7500

-1.3125

J = 11.5000 -12.0000 12.5000

6.0000 17.7500 -3.0000

-5.2500 6.2500 0.2500

dx = -2.4829

-2.2213

-1.8582

x = 3.2671

3.7787

4.3918

iter = 3

dc = -4.6834
-10.4491

0.4861

J = 6.5343 -7.5575 8.7836

3.7787 10.8246 -3.0000

-3.3918 4.3918 0.5116

dx = -1.0721

-0.6799

-0.3207

x = 2.1951

3.0988

4.0711

iter = 4

dc = -0.7899

-1.1913

0.1258
J = 4.3901 -6.1976 8.1423

3.0988 8.3927 -3.0000

-3.0711 4.0711 0.9037

dx = -0.1892

-0.0966

-0.0685

x = 2.0059

3.0022

4.0026

iter = 5

dc = -0.0312

-0.0276

0.0063

J = 4.0118 -6.0044 8.0052

3.0022 8.0103 -3.0000

-3.0026 4.0026 0.9963


dx = -0.0059

-0.0022

-0.0026

x = 2.0000

3.0000

4.0000

iter = 6

dc = 1.0e-04 *

-0.3669

-0.1784

0.0957

J = 4.0000 -6.0000 8.0000

3.0000 8.0000 -3.0000

-3.0000 4.0000 1.0000


dx = 1.0e-05 *

-0.5577

-0.1130

-0.2645

x = 2.0000

3.0000

4.0000

>>
CODE FOR GAUSS SEIDEL METHOD
x =[0,0,0];
x(1)=1/2*(0-3*x(2)-4*x(3));
x(2)=1/8*(11-6*x(1)-5*x(3));
x(3)=1/6*(12-2*x(1)-9*x(2));
for i=1:21
x(1)=1/2*(10-3*x(2)-4*x(3));
x(2)=1/8*(11-6*x(1)-5*x(3));
x(3)=1/6*(12-2*x(1)-9*x(2));
end
disp(x);

OUTPUT

>> gss
0.3000 -0.6000 2.8000
CODE FOR Y-BUS FORMATION BY INSPECTION METHOD
function[Y]=ybusformation_userinput()
prompt='Enter the number of branches \n ';
branches=input(prompt);
for g=1:branches
% prompt ='Enter the data for line number ';
%zdata1=input('Enter the data for all lines \n');
zdata(g,1)=input('Enter starting bus number ');
zdata(g,2)=input('Enter ending bus number ');
zdata(g,3)=input('Enter resistance value ');
zdata(g,4)=input('Enter the reactance value ');
end
nl=zdata(:,1); nr=zdata(:,2); R=zdata(:,3); X=zdata(:,4);
nbr=length(zdata(:,1)); nbus=max(max(nl),max(nr));
Z=R+j*X; %BRANCH IMPEDANCE
y=ones(nbr,1)./Z; %BRANCH ADMITTANCE
Y=zeros(nbus,nbus); %INITIALIZE Y TO ZERO
for k=1:nbr; %FORMATION OF THE OFF DIAGONAL ELEMENT
if nl(k)>0 & nr(k)>0
Y(nl(k),nr(k))=Y(nl(k),nr(k))-y(k);
Y(nr(k),nl(k))=Y(nl(k),nr(k));
end
end
for n= 1:nbus %FORMATION OF THE DIAGONAL ELEMENT
for k=1:nbr
if nl(k)==n|nr(k)==n
Y(n,n)=Y(n,n)+ y(k);
else, end
end
end
OUTPUT
>> ybusformation_userinput
Enter the number of branches
6
Enter starting bus number 0
Enter ending bus number 1
Enter resistance value 0
Enter the reactance value 1
Enter starting bus number 0
Enter ending bus number 2
Enter resistance value 0
Enter the reactance value 0.8
Enter starting bus number 1
Enter ending bus number 2
Enter resistance value 0
Enter the reactance value 0.4
Enter starting bus number 1
Enter ending bus number 3
Enter resistance value 0
Enter the reactance value 0.2
Enter starting bus number 2
Enter ending bus number 3
Enter resistance value 0
Enter the reactance value 0.2
Enter starting bus number 3
Enter ending bus number 4
Enter resistance value 0
Enter the reactance value 0.08
ans =

0.0000 - 8.5000i 0.0000 + 2.5000i 0.0000 + 5.0000i 0.0000 + 0.0000i

0.0000 + 2.5000i 0.0000 - 8.7500i 0.0000 + 5.0000i 0.0000 + 0.0000i

0.0000 + 5.0000i 0.0000 + 5.0000i 0.0000 -22.5000i 0.0000 + 12.5000i

0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 +12.5000i 0.0000 -12.5000i

>>
CODE FOR Y-BUS FORMATION BY SINGULAR
TRANFORMATION
function[Y]=ybusformation()
prompt='enter the number of branches= ';
branches=input(prompt);
for b=1:branches
zdata(b,1)=input('Enter "from" bus number= ');
zdata(b,2)=input('Enter "to" bus number= ');
zdata(b,3)=input('Enter resistance= ');
zdata(b,4)=input('Enter reactance= ');
end
fb=zdata(:,1);
tb=zdata(:,2);
R=zdata(:,3);
X=zdata(:,4);
Z=R+j*X;
buses=max(max(fb),max(tb));

%primitive admittance matrix


padm=zeros(branches,branches);
for c=1:branches
padm(c,c)=1/Z(c);

end

%bus incidence matrix


binm=zeros(branches,buses);
for d=1:branches
if fb(d)==0
binm(d,tb(d))=-1;
elseif tb(d)==0
binm(d,fb(d))=1;
else
binm(d,tb(d))=-1;
binm(d,fb(d))=1;
end
end
ybus=(binm')*(padm)*(binm);
display(ybus);
end

OUTPUT
>> ybusformation
enter the number of branches= 6
Enter "from" bus number= 0
Enter "to" bus number= 1
Enter resistance= 0
Enter reactance= 1
Enter "from" bus number= 0
Enter "to" bus number= 2
Enter resistance= 0
Enter reactance= 0.8
Enter "from" bus number= 1
Enter "to" bus number= 2
Enter resistance= 0
Enter reactance= 0.4
Enter "from" bus number= 1
Enter "to" bus number= 3
Enter resistance= 0
Enter reactance= 0.2
Enter "from" bus number= 2
Enter "to" bus number= 3
Enter resistance= 0
Enter reactance= 0.2
Enter "from" bus number= 3
Enter "to" bus number= 4
Enter resistance= 0
Enter reactance= 0.08

ybus =

0.0000 - 8.5000i 0.0000 + 2.5000i 0.0000 + 5.0000i 0.0000 + 0.0000i


0.0000 + 2.5000i 0.0000 - 8.7500i 0.0000 + 5.0000i 0.0000 + 0.0000i
0.0000 + 5.0000i 0.0000 + 5.0000i 0.0000 -22.5000i 0.0000 +12.5000i
0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 +12.5000i 0.0000 -12.5000i

>>
CODE FOR LOAD FLOW STUDIES BY GAUSS SEIDEL METHOD
%GAUSS WITHOUT PV BUS
clc
clear all
n=input('Number of buses=');
base=input('enter the base value');

for k=1:n
for L=1:n
y(k,L)=0;
end
end

for k=1:n
for L=k+1:n
fprintf('R%i%i=',k,L);
R(k,L)=input('');
fprintf('X%i%i=',k,L);
X(k,L)=input('');
y(k,L)=1/(R(k,L)+1i*X(k,L));
y(L,k)=y(k,L);
end
end

for k=1:n
for L=1:n
if k==L
Y(k,k)=0;
for m=1:n
Y(k,k)=Y(k,k)+y(k,m);
end
else
Y(k,L)=-y(k,L);
end
end
end
disp(['For bus 1(Slack bus)']);
V(1)=input('Voltage of the bus=');

for k=2:n
fprintf('\n');
disp(['For bus ',num2str(k)]);

P(k)=input(' Active Power Injected=')/base;


Q(k)=input('Reactive Power Injected=')/base;
end

for k=2:n

V(k)=1;

end
display(Y);
display(P);
display(Q);
tol=10;
iter=1;
Vprev=V;
while (tol>0.00001 | iter==1),

Vprev=V;
for i=2:n
sumyv=0;
for k=1:n,
if(i~=k)
sumyv=sumyv+Y(i,k)*V(k);
end
end
V(i)=(1/Y(i,i))*((P(i)-j*Q(i))/conj(V(i))-sumyv);
end
tol=max(abs(abs(V(2:n))-abs(Vprev(2:n))));
V
iter=iter+1
end

OUTPUT
Number of buses=3
enter the base value100
R12=0.02
X12=0.04
R13=0.01
X13=0.03
R23=0.0125
X23=0.025
For bus 1(Slack bus)
Voltage of the bus=1

For bus 2
Active Power Injected=-256.6
Reactive Power Injected=-110.2

For bus 3
Active Power Injected=-138.6
Reactive Power Injected=-45.2

Y =
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

P =

0 -2.5660 -1.3860

Q =

0 -1.1020 -0.4520

V = 1.0000 + 0.0000i 0.9633 - 0.0310i 0.9674 - 0.0342i

iter = 2

V =1.0000 + 0.0000i 0.9409 - 0.0520i 0.9552 - 0.0461i

iter = 3

V =1.0000 + 0.0000i 0.9317 - 0.0591i 0.9502 - 0.0502i

iter = 4

V =1.0000 + 0.0000i 0.9280 - 0.0615i 0.9482 - 0.0517i


iter = 5

V =1.0000 + 0.0000i 0.9265 - 0.0624i 0.9474 - 0.0522i

iter = 6

V =1.0000 + 0.0000i 0.9259 - 0.0628i 0.9470 - 0.0524i

iter = 7

V =1.0000 + 0.0000i 0.9257 - 0.0629i 0.9469 - 0.0525i

iter = 8

V =1.0000 + 0.0000i 0.9256 - 0.0629i 0.9468 - 0.0525i

iter = 9

V =1.0000 + 0.0000i 0.9256 - 0.0630i 0.9468 - 0.0525i

iter = 10

V =1.0000 + 0.0000i 0.9255 - 0.0630i 0.9468 - 0.0525i


iter = 11

V =1.0000 + 0.0000i 0.9255 - 0.0630i 0.9468 - 0.0525i

iter = 12

>>
CODE FOR LOAD FLOW STUDIES BY NR METHOD
v=[1.05;1.0;1.04];
d=[0;0;0];
ps=[-4;2.0];
qs=-2.5;
n= input('Enter the number of buses ');
fprintf('Enter your choice');
p= input ('1. impedance, 2. admittance');
if (p==1)
for q= 1:n
for r=q+1:n
fprintf('Enter the impedance value between %d-%d',q,r);
z(q,r)=input(':');
if (z(q,r)==0)
y(q,r)=0;
else
y(q,r)=inv(z(q,r));
end
y(r,q)= y(q,r);
end
end
elseif (p==2)
for a= 1:n
for b=a+1:n
fprintf('Enter the admittance value between %d-%d',a,b);
y(a,b)=input(':');
y(b,a)= y(a,b);
end
end
else
fprintf('enter the correct choice');
end
ybus=zeros(n,n);
for a = 1:n
for b=1:n
if (a==b)
for c = 1:n
ybus(a,a)= ybus(a,a)+ y(a,c);
end
else
ybus(a,b)=-y(b,a);
end
end
end
y=abs(ybus); t=angle(ybus);
iter=0;
pwracur=0.00025;% Power accuracy
dc=10;% Set the maximum power residual to a high value

while max(abs(dc))>pwracur
iter=iter+1
p=[v(2)*v(1)*y(2,1)*cos(t(2,1)-
d(2)+d(1))+v(2)^2*y(2,2)*cos(t(2,2))+v(2)*v(3)*y(2,3)*cos(t(2,3)-d(2)+d(3));
v(3)*v(1)*y(3,1)*cos(t(3,1)-
d(3)+d(1))+v(3)^2*y(3,3)*cos(t(3,3))+v(3)*v(2)*y(3,2)*cos(t(3,2)-d(3)+d(2))];
q=-v(2)*v(1)*y(2,1)*sin(t(2,1)-d(2)+d(1))-v(2)^2*y(2,2)*sin(t(2,2))-
v(2)*v(3)*y(2,3)*sin(t(2,3)-d(2)+d(3));
j(1,1)=v(2)*v(1)*y(2,1)*sin(t(2,1)-d(2)+d(1))+v(2)*v(3)*y(2,3)*sin(t(2,3)-d(2)+d(3));
j(1,2)=-v(2)*v(3)*y(2,3)*sin(t(2,3)-d(2)+d(3));
j(1,3)=v(1)*y(2,1)*cos(t(2,1)-
d(2)+d(1))+2*v(2)*y(2,2)*cos(t(2,2))+v(3)*y(2,3)*cos(t(2,3)-d(2)+d(3));
j(2,1)=-v(3)*v(2)*y(3,2)*sin(t(3,2)-d(3)+d(2));
j(2,2)=v(3)*v(1)*y(3,1)*sin(t(3,2)-d(3)+d(1))+v(3)*v(2)*y(3,2)*sin(t(3,2)-d(3)+d(2));
j(2,3)=v(3)*y(2,3)*cos(t(3,2)-d(3)+d(2));
j(3,1)=v(2)*v(1)*y(2,1)*cos(t(2,1)-d(2)+d(1))+v(2)*v(3)*y(2,3)*cos(t(2,3)-d(2)+d(3));
j(3,2)=-v(2)*v(3)*y(2,3)*cos(t(3,2)-d(2)+d(3));
j(3,3)=-v(1)*y(2,1)*sin(t(2,1)-d(2)+d(1))-2*v(2)*y(2,2)*sin(t(2,2))-
v(3)*y(2,3)*sin(t(2,3)-d(2)+d(3));
dp=ps-p;
dq=qs-q;
dc=[dp;dq]
j
dx=j\dc
d(2)=d(2)+dx(1);
d(3)=d(3)+dx(2);
v(2)=v(2)+dx(3);
v,d,delta=180/pi*d;
end
p1=v(1)^2*y(1,1)*cos(t(1,1))+v(1)*v(2)*y(1,2)*cos(t(1,2)-
d(1)+d(2))+v(1)*v(3)*y(1,3)*cos(t(1,3)-d(1)+d(3))
q1=-v(1)^2*y(1,1)*sin(t(1,1))-v(1)*v(2)*y(1,2)*sin(t(1,2)-d(1)+d(2))-
v(1)*v(3)*y(1,3)*sin(t(1,3)-d(1)+d(3))
q3=-v(3)*v(1)*y(3,1)*sin(t(3,1)-d(3)+d(1))-v(3)*v(2)*y(3,2)*sin(t(3,2)-d(3)+d(2))-v(3)^2*y(3,3)*sin(t(3,3))
OUTPUT
Enter the number of buses 3

Enter your choice1. impedance, 2. admittance2

Enter the admittance value between 1-2:10-20i

Enter the admittance value between 1-3:10-30i

Enter the admittance value between 2-3:16-32i

iter =1

dc = -2.8600

1.4384

-0.2200

j=

54.2800 -33.2800 24.8600

-33.2800 64.1664 -16.6400

-27.1400 16.6400 49.7200


dx =

-0.0455

-0.0080

-0.0265

v=

1.0500

0.9735

1.0400

d=

-0.0455

-0.0080

iter =

dc =

-0.0992

0.0367

-0.0509
j=

51.7246 -31.7678 21.3026

-32.9797 63.7409 -15.3834

-28.5386 17.3988 48.1036

dx =

-0.0016

-0.0007

-0.0018

v=

1.0500

0.9717

1.0400

d=

-0.0471
-0.0087

iter = 3

dc =

-0.0002

0.0014

-0.0001

j = 51.5967 -31.6941 21.1474

-32.9337 63.6841 -15.3520

-28.5482 17.3966 47.9549

dx =

1.0e-04 *

0.1465

0.2778

-0.0428

v=

1.0500

0.9717
1.0400

d=

-0.0471

-0.0087

iter = 4

dc =

1.0e-04 *

-0.0000

-0.5314

-0.0001

j=

51.5964 -31.6937 21.1471

-32.9337 63.6846 -15.3516

-28.5482 17.3969 47.9545

dx =
1.0e-05 *

-0.0750

-0.1223

-0.0003

v=

1.0500

0.9717

1.0400

d=

-0.0471

-0.0087

p1 =

2.1842

q1 =

1.4085

q3 =

1.4618

You might also like