You are on page 1of 2

COMPLEX ENGINEERING PROBLEM

POWER SYSTEMS ANALYSIS AND DESIGNs LAB

SHAHAB JAVED
F2016019007
SECTION: A2

GENERAL CODE FOR GAUSS SIEDAL METHOD:

% formation of Y matrix of bus network


clc
clear all
n=input('enter no. of buses:'); % no. of buses excluding reference
nl= input('enter no. of lines:'); % no. of transmission lines
sb= input('enter starting bus of each line:'); % starting bus of a line
eb= input('enter ending bus of each line:'); % ending bus of a line
zser= input('enter resistance and reactance of each line:'); % line resistance and reactance (R, X)
yshty= input('enter shunt admittance of the bus:'); % shunt admittance

i=0;
k=1;

while i<nl
zser1(i+1)=zser(k)+j*zser(k+1); % impedance of a line (R+jX)
i=i+1;
k=k+2;
end

zser2=reshape(zser1,nl,1);% rearranging line impedance


yser=ones(nl,1)./zser2;%inverse of impedances is admitance
ybus=zeros(n,n);% initial lizing of new Y MATRIX with zeros

for i=1:nl
ybus(sb(i),sb(i))=ybus(sb(i),sb(i))+yser(i);% for diagonals
ybus(eb(i),eb(i))=ybus(eb(i),eb(i))+yser(i);
ybus(sb(i),eb(i))=-yser(i);% for anti diagonals
ybus(eb(i),sb(i))=-yser(i);
end

ybus

%gauss seidal start from here


Y=ybus;
pu=input('enter the base value in MVA: ');%per unit vale of power
for bus=1:length(Y)%data collection of each bus from the network
bus
v=input('enter the voltage of current bus: ');
p=input('enter real power of current bus in MW: ');
q=input('enter reactive power of current bus in MVAR: ');
data(bus,:)=[v p./pu q./pu];
end

%making row matrix of V P and Q


V=reshape(data(:,1),1,3);
P=reshape(data(:,2),1,3);
Q=reshape(data(:,3),1,3);
n=length(Y);
diff=0;
iter=1;
Vprev=V;

while (diff>=0.00001 || iter==1) % loop will terminat when difference of voltages were less that
0.00001
abs(V);
abs(Vprev);
Vprev=V;

for i=2:n %i represent the each bus in nth bus network


sumyv=0;
for k=1:n
if(i~=k) %in summation we were not take i=k or at current bus
sumyv=sumyv+Y(i,k)*V(k);
end
end

V(i)=(1/Y(i,i))*((P(i)-j*Q(i))/conj(V(i))-sumyv); %drive from taking KCL at each node in


the network
end

diff=max(abs(abs(V(2:n))-abs(Vprev(2:n)))); % taking difference of voltages after each


iteration
iter=iter+1 %increment of iteration
V
end

You might also like