### C Agarwal (view profile)

04 Jan 2008 (Updated )

Gauss Siedel method having infinite iterations

Gausssiedel_infinite.m
```% Gauss Siedel Load Flow Analysis for infinite number of iterations.
%Chinmay Agarwal 21/10/2007
%Indian Institute of Technology Delhi
%User to modify -----------------------------------------------portions only
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear
disp('Enter the following parameters :')
n = 4%input('Number of buses, n = '); % n=4   -----------------------------------------------------------
V = [1.04 1.04 1 1] %input('Bus voltages, V = '); % [1.04 1.04 1 1] -----------------------------------------

type = [1 2 1 1] %input('Type of buses (1-PQ/Slack, 2-PV) type = ');   % [1 2 1 1] --------------------------------
P = [inf 0.5 -1 0.3] %input('Real powers, P = '); % [inf 0.5 -1 0.3]; ---------------------------------------------
Q = [inf -0.2 0.5 -0.1] %input('Reactive powers, Q = '); % [inf -0.2 0.5 -0.1]; ------------------------------------
Y = [3-9i -2+6i -1+3i 0; -2+6i 3.666-11i -0.666+2i -1+3i; -1+3i -0.666+2i 3.666-11i -2+6i; 0 -1+3i -2+6i 3-9i] %input('Y matrix, Y = '); % [3-9i -2+6i -1+3i 0; -2+6i 3.66-11i -0.66+2i -1+3i; -1+3i -0.66+2i 3.66-11i -2+6i; 0 -1+3i -2+6i 3-9i];

Qmax = zeros(n,1);
Qmin = zeros(n,1);
Vmagfixed=zeros(n,1);
typechanged=zeros(n,1);
Vinput = V;
for i = 2:n,
if type(i) == 2,
disp(sprintf('For bus %d :', i))
Qmax(i) = 1 %input('QlimitMax = '); % 1
Qmin(i) = 0.25 %input('QlimitMin = '); % 0.25
Vmagfixed(i) = 1.04 %input('Vmagnitudefixed = ');%1.04
end
end

diff = 10; iterationnumber=1;
iterationnumbermax=30; %----------------------------------------------------
Vprev=V;
while(diff>.0001 & iterationnumber<iterationnumbermax )  %------------------------------------------------------------

abs(V);
abs(Vprev);
Vprev=V;
for i = 2:n,
sumyv = 0;
for k = 1:n,
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) = 1;
V(i)=1;
end
end

V(i) = (1/Y(i,i))*((P(i)-j*Q(i))/conj(V(i)) - sumyv);
if type(i) ==  2,
V(i) = Vmagfixed(i)*cos(angle(V(i))*180/pi*pi/180) + j*Vmagfixed(i)*sin(angle(V(i))*180/pi*pi/180);
end
end
diff=max(abs(abs(V(2:n))-abs(Vprev(2:n))));
iterationnumber   %display on-off--------------------------------------------------------------------------------
iterationnumber=iterationnumber+1;
V   %display on-off--------------------------------------------------------------------------------
end
disp(sprintf('----------------------------------------------------------------------'))
disp(sprintf('----------------Solution to Problem-----------------------------------'))
disp(sprintf('----------------------------------------------------------------------'))
Vinput
V
delta = angle(V)
disp(sprintf('----------------------------------------------------------------------'))
disp(sprintf('----------------------------------------------------------------------'))
```