100% found this document useful (1 vote)
120 views5 pages

Cse QP

This function performs a Gauss-Seidel power flow calculation to solve for bus voltages given a bus data matrix, line data matrix, initial voltages, and lists of PV and PQ buses. It initializes matrices, builds the bus admittance matrix, reads the bus data, then iteratively updates voltages at PQ and PV buses until the voltage mismatches converge within a specified tolerance or the maximum number of iterations is reached.

Uploaded by

Anand Kal
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)
120 views5 pages

Cse QP

This function performs a Gauss-Seidel power flow calculation to solve for bus voltages given a bus data matrix, line data matrix, initial voltages, and lists of PV and PQ buses. It initializes matrices, builds the bus admittance matrix, reads the bus data, then iteratively updates voltages at PQ and PV buses until the voltage mismatches converge within a specified tolerance or the maximum number of iterations is reached.

Uploaded by

Anand Kal
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/ 5

%function [V, converged, i] = gausspf(Ybus, Sbus, V0, ref, pv, pq, mpopt)

%% initialize
converged = 0;
basemva = 100; accuracy = 0.01; maxit = 100;
% IEEE 30 – BUS TEST SYSTEM (American Electric Power)
%Bus Bus Voltage Angle --- Load --- ----------- Generator ----- Injected
%No Code Mag. Degree MW Mvar MW Mvar Qmin Qmax Mvar
busdata= [...
1 1 1.05 0.0 0.0 0.0 0.0 0.0 -20 100 0
2 2 1.05 0.0 21.70 12.7 40.0 0.0 -20 60 0
3 0 1.0 0.0 2.4 1.2 0.0 0.0 0 0 0
4 0 1.0 0.0 7.6 1.6 0.0 0.0 0.0 0 0
5 2 1.05 0.0 94.2 19.0 0.0 0.0 -15 62.5 0
6 0 1.0 0.0 0.0 0.0 0.0 0.0 0 0 0
7 0 1.0 0.0 22.8 10.9 0.0 0.0 0 0 0
8 2 1.05 0.0 30.0 30.0 0.0 0.0 -15 50 0
9 0 1.0 0.0 0.0 0.0 0.0 0.0 0 0 0
10 0 1.0 0.0 5.8 2.0 0.0 0.0 -10 40 00
11 2 1.05 0.0 0.0 0.0 0.0 0.0 0 0 0
12 0 1.0 0 11.2 7.5 0 0 0 0 0
13 2 1.05 0 0 0.0 0. 0 -15 45 0
14 0 1 0 6.2 1.6 0 0 0 0 0
15 0 1 0 8.2 2.5 0 0 0 0 0
16 0 1 0 3.5 1.8 0 0 0 0 0
17 0 1 0 9.0 5.8 0 0 0 0 0
18 0 1 0 3.2 0.9 0 0 0 0 0
19 0 1 0 9.5 3.4 0 0 0 0 0
20 0 1 0 2.2 0.7 0 0 0 0 0
21 0 1 0 17.5 11.2 0 0 0 0 0
22 0 1 0 0 0.0 0 0 0 0 00
23 0 1 0 3.2 1.6 0 0 0 0 0
24 0 1 0 8.7 6.7 0 0 0 0 0
25 0 1 0 0 0 0 0 0 0 0
26 0 1 0 3.5 2.3 0 0 0 0 0
27 0 1 0 0 0.0 0 0 0 0 0
28 0 1 0 0 0.0 0 0 0 0 0
29 0 1 0 2.4 0.9 0 0 0 0 0
30 0 1 0 10.6 1.9 0 0 0 0 0];
% Line Code
%Bus bus R X ½B= 1 for lines
%n1 nr p.u. p.u. > 1 or < 1 tr.
% Tap at bus n1

linedata=[ ...
1 2 0.0192 0.0575 0.02640 1
1 3 0.0452 0.1852 0.02040 1
2 4 0.570 0.1737 0.01840 1
3 4 0.0132 0.0379 0.00420 1
2 5 0.0472 0.1983 0.02090 1
2 6 0.0581 0.1763 0.01870 1
4 6 0.0119 0.0414 0.00450 1
5 7 0.0460 0.1160 0.01020 1
6 7 0.0267 0.0820 0.00850 1
6 8 0.0120 0.0420 0.00450 1
6 9 0.0 0.2080 0.0 1
6 10 0 .5560 0 1.0
9 11 0 .2080 0 1.0
9 10 0 .1100 0 1
4 12 0 .2560 0 1
12 13 0 .1400 0 1.0
12 14 .1231 .2559 0 1
12 15 .0662 .1304 0 1
12 16 .0945 .1987 0 1
14 15 .2210 .1997 0 1
16 17 .0824 .1923 0 1
15 18 .1073 .2185 0 1
18 19 .0639 .1292 0 1
19 20 .0340 .0680 0 1
10 20 .0936 .2090 0 1
10 17 .0324 .0845 0 1
10 21 .0348 .0749 0 1
10 22 .0727 .1499 0 1
21 22 .0116 .0236 0 1
15 23 .1000 .2020 0 1
22 24 .1150 .1790 0 1
23 24 .1320 .2700 0 1
24 25 .1885 .3292 0 1
25 26 .2544 .3800 0 1
25 27 .1093 .2087 0 1
28 27 0 .3960 0 1.0
27 29 .2198 .4153 0 1
27 30 .3202 .6027 0 1
29 30 .2399 .4533 0 1
8 28 .0636 .2000 0.0214 1
6 28 .0169 .0599 0.065 1];

j=sqrt(-1);
nline=length(linedata(:,1));
nbus=length(busdata(:,1));

for k=1:nline
nl(k)=linedata(k,1);
nr(k)=linedata(k,2);
r(k)=linedata(k,3);
x(k)=linedata(k,4);
ysh(k)=linedata(k,5);
%a(k)=linedata(k,6);
z(k)=r(k)+j*x(k);
y(k)=1/z(k);
end

a=linedata(:,6);
Ybus=zeros(nbus,nbus);
for k=1:nline
ynl(k)=(1/(a(k)*a(k))-(1/a(k)))*y(k);
ynr(k)=(1-(1/a(k)))*y(k);
y(k)=y(k)/a(k);
end

for k=1:nline
Ybus(nl(k),nr(k))=Ybus(nl(k),nr(k))-y(k);
Ybus(nr(k),nl(k))=Ybus(nl(k),nr(k));
Ybus(nl(k),nl(k))=Ybus(nl(k),nl(k))+y(k)+ynl(k)+j*ysh(k);
Ybus(nr(k),nr(k))=Ybus(nr(k),nr(k))+y(k)+ynr(k)+j*ysh(k);
end
Ybus
%
%
%% Read bus data
nbus = length(busdata(:,1));
for k=1:nbus
n=busdata(k,1);
kb(n)=busdata(k,2);Vm(n,1)=busdata(k,3); delta(n,1)=busdata(k,4);
Pd(n,1)=busdata(k,5); Qd(n,1)=busdata(k,6); Pg(n,1)=busdata(k,7);
Qg(n,1) = busdata(k,8);
Qmin(n,1)=busdata(k,9); Qmax(n,1)=busdata(k,10);
Qsh(n,1)=busdata(k,11);
V(n,1)=Vm(n,1)* (cos(delta(n,1)) + j* sin(delta(n,1)));
P(n,1)=(Pg(n,1)-Pd(n,1))/basemva;
Q(n,1)=(Qg(n,1)-Qd(n,1)+Qsh(n,1))/basemva;
Sbus(n,1) = P(n,1) + j* Q(n,1);
end

pv=[2;5;8;11;13];
pq=[3;4;6;7;9;10;12;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;30];
npv=5;
npq=24
%Pd=1.75*Pd
Va=delta;
%Ybus=Ybus([1;pv;pq],[1;pv;pq]);
Bp=-imag(Ybus([pv;pq],[pv;pq]));
Bpp=-imag(Ybus(pq,pq));
%
mis=(V.*conj(Ybus*V)-Sbus)./Vm;
%intial mismatch of P,Q
P=real(mis([pv;pq]));
Q=imag(mis(pq));
converged=0;
i=0;
tol=0.001;
F = [ real(mis([pv; pq]));
imag(mis(pq)) ];

%% do Gauss-Seidel iterations
while (~converged & i < maxit)
%% update iteration counter
i = i + 1;

%% update voltage
%% at PQ buses
for k = pq(1:npq)'
V(k) = V(k) + (conj(Sbus(k) / V(k)) - Ybus(k,:) * V ) / Ybus(k,k);
end

%% at PV buses
if npv
for k = pv(1:npv)'
Sbus(k) = real(Sbus(k)) + 1j * imag( V(k) .* conj(Ybus(k,:) * V));
V(k) = V(k) + (conj(Sbus(k) / V(k)) - Ybus(k,:) * V ) / Ybus(k,k);
% V(k) = Vm(k) * V(k) / abs(V(k));
end
V(pv) = Vm(pv) .* V(pv) ./ abs(V(pv));
end

%% evalute F(x)
mis = V .* conj(Ybus * V) - Sbus;
F = [ real(mis(pv));
real(mis(pq));
imag(mis(pq)) ];

%% check for convergence


normF = norm(F, inf);

if normF < tol


converged = 1;
i
end
end

Vmag=abs(V)
Vang=angle(V)

You might also like