0% found this document useful (0 votes)
15 views10 pages

Assignment 3

The document contains MATLAB code for constructing the admittance matrix (Ybus) for a power system based on given line and bus data. It calculates power flow using the Newton-Raphson method, iterating until convergence is achieved. The results include the calculated power (P), reactive power (Q), voltage magnitudes (V), and phase angles (delta) for each bus in the system.

Uploaded by

shubhangim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views10 pages

Assignment 3

The document contains MATLAB code for constructing the admittance matrix (Ybus) for a power system based on given line and bus data. It calculates power flow using the Newton-Raphson method, iterating until convergence is achieved. The results include the calculated power (P), reactive power (Q), voltage magnitudes (V), and phase angles (delta) for each bus in the system.

Uploaded by

shubhangim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

clc;

clear all;

close all;

linedata=[

1 1 2 0.0194 0.0592 0.0528 0


2 1 5 0.054 0.223 0.0492 0
3 2 3 0.047 0.1979 0.0438 0
4 2 4 0.0581 0.1763 0.0374 0
5 2 5 0.0569 0.1738 0.0339 0
6 3 4 0.067 0.171 0.0346 0
7 4 5 0.0134 0.0421 0.0128 0
8 4 7 0 0.209 0 1
9 4 9 0 0.5562 0 1
10 5 6 0 0.2522 0 1
11 6 11 0.095 0.1989 0 0
12 6 12 0.1229 0.2557 0 0
13 6 13 0.0661 0.1302 0 0
14 7 8 0 0.1762 0 1
15 7 9 0 0.011 0 1
16 9 10 0.0318 0.0845 0 0
17 9 14 0.127 0.2703 0 0
18 10 11 0.082 0.192 0 0
19 12 13 0.2209 0.1999 0 0
20 13 14 0.1709 0.3479 0 0
];

nb = max(max(linedata(:,2)), max(linedata(:,3)));

nb

n = length(linedata)

Ybus = zeros(nb);

for a = 1:size(linedata, 1)

from = linedata(a, 2);

to = linedata(a, 3);
R = linedata(a, 4);

X = linedata(a, 5);

B_half = linedata(a, 6);

tap = linedata(a, 7);

Z = R + 1i*X;

Y = 1 / Z;

if tap ~=0

Ybus(from, from) = Ybus(from, from) + abs((tap)^2)*Y+ 1i*B_half;

Ybus(to, to) = Ybus(to, to) + Y + 1i*B_half;

Ybus(from, to) = Ybus(from, to) -conj(tap)* Y+ 1i*B_half;

Ybus(to, from) = Ybus(to, from) +(-tap)* Y+ 1i*B_half;

else

Ybus(from, from) = Ybus(from, from) + Y + 1i*B_half;

Ybus(to, to) = Ybus(to, to) + Y + 1i*B_half;

Ybus(from, to) = Ybus(from, to) - Y;

Ybus(to, from) = Ybus(to, from) - Y;

end

end

disp('Y bus matrix:');

disp(Ybus);

g = real(Ybus)

b = imag(Ybus)
% Bus No Bus Type |V| delta Pg Qg Pd Qd Qmin Qmax G_sh, B_sh

busdata = [

1 1 1.06 0 0 0 0 0 0 0 0 0
2 2 1.045 0 18.3 5.857 0 0 -500 500 0 0
3 3 1 0 0 0 119 8.762 0 0 0.0002 0.502
4 3 1 0 0 0 47.79 3.9 0 500 0 0
5 3 1 0 0 0 7.599 1.599 0 0 0 0
6 2 1.07 0 11.2 44.2 0 0 -500 500 0 0
7 3 1 0 0 0 0 0 0 0 0 0
8 3 1 0 0 0 0 12.9 0 0 0.0023 0.1325
9 3 1 0 0 0 29.499 16.599 0 0 0 0.0633
10 3 1 0 0 0 9 5.799 0 0 0 0
11 3 1 0 0 0 3.501 1.8 0 500 0 0
12 3 1 0 0 0 6.099 1.599 0 0 0 0
13 3 1 0 0 0 13.5 5.799 0 0 0 0
14 3 1 0 0 0 14.901 5.001 0 0 0 0
BaseMVA=100
];

type = busdata(:,2);

Vmag = busdata(:,3); del = busdata(:,4);

Pg = busdata(:,5); Qg = busdata(:,6);

Pd = busdata(:,7); Qd = busdata(:,8);

Qmin=busdata(:,9)/100; Qmax = busdata(:,10)/100;

G_sh = busdata(:,11) ;B_sh = busdata(:,12);

v= Vmag.*(cos(del) +1i*sin(del));

bmva=100;% base mva

P=(Pg-Pd)/bmva;

Q=(Qg-Qd)/bmva;

Vmag=abs(v);

y=abs(Ybus);

alpha=angle(Ybus);

e=real(v);

f=imag(v);
clear all;

ybusData;

Bus_Data;

g=real(Ybus);

b=imag(Ybus);

Psp=P;

Qsp=Q;

Vsp=Vmag;

p=zeros(nb,1);

q=zeros(nb,1);

Vsq=zeros(nb,1);

%n = 7 % no of branch

e = zeros(n,1);

f = zeros(n,1);

tol=1e-2;

iter=0;

error=inf;

L=0;%LOAD BUS = PQ BUS

Vb=0;

while error>tol

e=real(v);

f=imag(v);

for n=1:nb

if type(n)==2

Vsq(n)=(e(n))^2+(f(n))^2;

end

end

for n=1:nb
p(n)=0;

q(n)=0;

for k=1:nb

p(n)=p(n)+((e(n)*e(k)*g(n,k))-(e(n)*f(k)*b(n,k))+(f(n)*e(k)*b(n,k))+(f(n)*f(k)*g(n,k)));

q(n)=q(n)+((f(n)*e(k)*g(n,k))-(f(n)*f(k)*b(n,k))-(e(n)*e(k)*b(n,k))-(e(n)*f(k)*g(n,k)));

end

end

for n=1:nb

if type(n)==2

if q(n)<Qmin(n)

Qsp(n)=Qmin(n);

type(n)=3;

L=L+1;

Vb(L)=n;

elseif q(n)>Qmax(n)

Qsp(n)=Qmax(n);

type(n)=3;

L=L+1;

Vb(L)=n;

end

end

end

dP=Psp-p;

dQ=Qsp-q;

M=length(find(type==2 | type==1)); %% M= no. of generator

dP=dP(2:nb);

dQ=dQ(M+1:nb);
dVsq=Vsp(2:M).^2-Vsq(2:M);

for n=1:L

k=Vb(n);

MV(nb-M+n)=Qsp(k)-q(k);

end

MV=[dP ;dQ ;dVsq];% MV = MISMATCH VECTOR

error=max(abs(MV));

if error<tol

break

else

%% J1

J1=zeros(nb-1,nb-1);

for n=2:nb

A=0;

for k=2:nb

if k==n

for j=1:nb

if j~=n

A=A+((e(j)*g(n,j))-(f(j)*b(n,j)));

end

J1(n-1,k-1)=A+(2*e(n)*g(n,n));

end

else

J1(n-1,k-1)=(e(n)*g(n,k))+(f(n)*b(n,k));

end

end

end
%% J2

J2=zeros(nb-1,nb-1);

for n=2:nb

sum=0;

for k=2:nb

if k==n

for j=1:nb

if j~=n

sum=sum+((e(j)*b(j,n))+(f(j)*g(j,n)));

end

J2(n-1,k-1)=(2*f(n)*g(n,n))+sum;

end

else

J2(n-1,k-1)=-(e(n)*b(n,k))+(f(n)*g(n,k));

end

end

end

%%

M=length(find(type==2 | type==1)); %% M= no. of generator

J3=zeros(nb-M,nb-1);

%J3

for n=M+1:nb

sum=0;

for k=2:nb

if k==n

for j=1:nb

if j~=n

sum=sum+(e(j)*b(n,j))+(f(j)*g(n,j));
end

J3(n-M,k-1)=-sum-(2*e(n)*b(n,n));

end

else

J3(n-M,k-1)=(f(n)*g(n,k))-(e(n)*b(n,k));

end

end

end

J4=zeros(nb-M,nb-1);

%% J4

for n=M+1:nb

sum=0;

for k=2:nb

if k==n

for j=1:nb

if j~=n

sum=sum+((e(j)*g(n,j))-(f(j)*b(n,j)));

end

J4(n-M,k-1)=(-2*f(n)*b(n,n))+sum;

end

else

J4(n-M,k-1)=-1*(f(n)*b(n,k)+e(n)*g(n,k));

end

end

end

%%J5

J5=zeros(M-1,nb-1);

for n=2:M
for k=2:nb

if k==n

J5(n-1,k-1)=2*e(k);

else

J5(n-1,k-1)=0;

end

end

end

%%J6

J6=zeros(M-1,nb-1);

for n=2:M

for k=2:nb

if k==n

J6(n-1,k-1)=2*f(k);

else

J6(n-1,k-1)=0;

end

end

end

J=[J1 J2;J3 J4;J5 J6];

dX=inv(J)*MV;

de=dX(1:nb-1);

df=dX(nb:2*nb-2);

e(2:nb)=e(2:nb)+de;

f(2:nb)=f(2:nb)+df;

v=complex(e,f);

V=abs(v);

del=angle(v);
iter=iter+1;

end

end

iter

del

P Q V delta
2.3733 0 1.600 0
0.1830 -0.0898 1.0413 -0.0898
-1.1898 -0.2457 0.9795 -0.2457
-0.4779 -0.1772 1.0008 -0.1772
-0.0760 -0.1501 1.0165 -0.1501
0.1120 -0.2228 1.0429 -0.2228
0.000 -0.2331 0.9670 -0.2331
-0.000 -0.2331 0.9429 -0.2331
-0.2950 -0.2362 0.9668 -0.2362
-0.0900 -0.2389 0.9721 -0.2389
-0.0350 -0.2327 1.0030 -0.2327
-0.0610 -0.2394 1.0231 -0.2394
-0.1350 -0.2399 1.0135 -0.2399
-0.1490 -0.2576 0.9679 -0.2576

You might also like