0% found this document useful (0 votes)
146 views11 pages

Power Flow Solution by Newton-OK

The document describes using the Newton-Raphson method to solve a power flow problem. It initializes bus data including voltage magnitudes, voltage angles, loads, and generators. It then calculates the Jacobian matrix and mismatch vector at each iteration. The Jacobian is inverted to solve for voltage corrections, which are applied to update the voltages and angles. The process repeats until convergence within a specified tolerance is reached.
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
0% found this document useful (0 votes)
146 views11 pages

Power Flow Solution by Newton-OK

The document describes using the Newton-Raphson method to solve a power flow problem. It initializes bus data including voltage magnitudes, voltage angles, loads, and generators. It then calculates the Jacobian matrix and mismatch vector at each iteration. The Jacobian is inverted to solve for voltage corrections, which are applied to update the voltages and angles. The process repeats until convergence within a specified tolerance is reached.
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/ 11

% Power flow solution by Newton-Raphson

method
ns=0; ng=0; Vm=0; delta=0; yload=0; deltad=0;
nbus = length(busdata(:,1));
for k=1:nbus
n=busdata(k,1);
kb(n)=busdata(k,2); Vm(n)=busdata(k,3); delta(n)=busdata(k, 4);
Pd(n)=busdata(k,5); Qd(n)=busdata(k,6); Pg(n)=busdata(k,7); Qg(n) =
busdata(k,8);
Qmin(n)=busdata(k, 9); Qmax(n)=busdata(k, 10);
Qsh(n)=busdata(k, 11);
if Vm(n) <= 0 Vm(n) = 1.0; V(n) = 1 + j*0;
else delta(n) = pi/180*delta(n);
V(n) = Vm(n)*(cos(delta(n)) + j*sin(delta(n)));
P(n)=(Pg(n)-Pd(n))/basemva;
Q(n)=(Qg(n)-Qd(n)+ Qsh(n))/basemva;
S(n) = P(n) + j*Q(n);
end
end
for k=1:nbus
if kb(k) == 1, ns = ns+1; else, end
if kb(k) == 2 ng = ng+1; else, end
ngs(k) = ng;
nss(k) = ns;
end
Ym=abs(Ybus); t = angle(Ybus);
m=2*nbus-ng-2*ns;
maxerror = 1; converge=1;
iter = 0;
% Start of iterations
clear A DC J DX
while maxerror >= accuracy & iter <= maxiter % Test for max. power
mismatch
for i=1:m
for k=1:m
A(i,k)=0; %Initializing Jacobian matrix
end, end
iter = iter+1;
for n=1:nbus
nn=n-nss(n);
lm=nbus+n-ngs(n)-nss(n)-ns;
J11=0; J22=0; J33=0; J44=0;
for i=1:nbr
if nl(i) == n | nr(i) == n
if nl(i) == n, l = nr(i); end
if nr(i) == n, l = nl(i); end
J11=J11+ Vm(n)*Vm(l)*Ym(n,l)*sin(t(n,l)- delta(n) + delta(l));
J33=J33+ Vm(n)*Vm(l)*Ym(n,l)*cos(t(n,l)- delta(n) + delta(l));
if kb(n)~=1
J22=J22+ Vm(l)*Ym(n,l)*cos(t(n,l)- delta(n) + delta(l));
J44=J44+ Vm(l)*Ym(n,l)*sin(t(n,l)- delta(n) + delta(l));
else, endif kb(n) ~= 1 & kb(l) ~=1
lk = nbus+l-ngs(l)-nss(l)-ns;
ll = l -nss(l);
% off diagonalelements of J1
A(nn, ll) =-Vm(n)*Vm(l)*Ym(n,l)*sin(t(n,l)- delta(n) +
delta(l));
if kb(l) == 0 % off diagonal elements of J2
A(nn, lk) =Vm(n)*Ym(n,l)*cos(t(n,l)- delta(n) +
delta(l));end
if kb(n) == 0 % off diagonal elements of J3
A(lm, ll) =-Vm(n)*Vm(l)*Ym(n,l)*cos(t(n,l)-
delta(n)+delta(l)); end
if kb(n) == 0 & kb(l) == 0 % off diagonal elements of
J4
A(lm, lk) =-Vm(n)*Ym(n,l)*sin(t(n,l)- delta(n) +
delta(l));end
else end
else , end
end
Pk = Vm(n)^2*Ym(n,n)*cos(t(n,n))+J33;
Qk = -Vm(n)^2*Ym(n,n)*sin(t(n,n))-J11;
if kb(n) == 1 P(n)=Pk; Q(n) = Qk; end % Swing bus P
if kb(n) == 2 Q(n)=Qk;
if Qmax(n) ~= 0
Qgc = Q(n)*basemva + Qd(n) - Qsh(n);
if iter <= 7 % Between the 2th & 6th
iterations
if iter > 2 % the Mvar of generator buses
are
if Qgc < Qmin(n), % tested. If not within limits
Vm(n)
Vm(n) = Vm(n) + 0.01; % is changed in steps of 0.01
pu to
elseif Qgc > Qmax(n), % bring the generator Mvar
within
Vm(n) = Vm(n) - 0.01;end % the specified limits.
else, end
else,end
else,end
end
if kb(n) ~= 1
A(nn,nn) = J11; %diagonal elements of J1
DC(nn) = P(n)-Pk;
end
if kb(n) == 0
A(nn,lm) = 2*Vm(n)*Ym(n,n)*cos(t(n,n))+J22; %diagonal elements of
J2
A(lm,nn)= J33; %diagonal elements of J3
A(lm,lm) =-2*Vm(n)*Ym(n,n)*sin(t(n,n))-J44; %diagonal of elements
of J4
DC(lm) = Q(n)-Qk;
end
end
gx=A;
DX=A\DC';
for n=1:nbus
nn=n-nss(n);
lm=nbus+n-ngs(n)-nss(n)-ns; if kb(n) ~= 1
delta(n) = delta(n)+DX(nn); end
if kb(n) == 0
Vm(n)=Vm(n)+DX(lm); end
end
maxerror=max(abs(DC));
if iter == maxiter & maxerror > accuracy
fprintf('\nWARNING: Iterative solution did not converged after ')
fprintf('%g', iter), fprintf(' iterations.\n\n')
fprintf('Press Enter to terminate the iterations and print the
results \n')
converge = 0; pause, else, end
end
if converge ~= 1
tech= (' ITERATIVE SOLUTION DID NOT CONVERGE');
else,
tech=(' Newton-Raphson Power Flow Solution');
end
V = Vm.*cos(delta)+j*Vm.*sin(delta);
deltad=180/pi*delta;
i=sqrt(-1);
k=0;
for n = 1:nbus
if kb(n) == 1
k=k+1;
S(n)= P(n)+j*Q(n);
Pg(n) = P(n)*basemva + Pd(n);
Qg(n) = Q(n)*basemva + Qd(n) - Qsh(n);
Pgg(k)=Pg(n);
Qgg(k)=Qg(n); %june 97
elseif kb(n) ==2
k=k+1;
S(n)=P(n)+j*Q(n);
Qg(n) = Q(n)*basemva + Qd(n) - Qsh(n);
Pgg(k)=Pg(n);
Qgg(k)=Qg(n); % June 1997
end
yload(n) = (Pd(n)- j*Qd(n)+j*Qsh(n))/(basemva*Vm(n)^2);
end
busdata(:,3)=Vm'; busdata(:,4)=deltad';
Pgt = sum(Pg); Qgt = sum(Qg); Pdt = sum(Pd); Qdt = sum(Qd); Qsht =
sum(Qsh);
inv(A);
Vm(4);
deltad(4);
Vm(2)*YL(1,2)
Vm(3)*gx;
plot(Vm)
grid on
%clear A DC DX J11 J22 J33 J44 Qk delta lk ll lm
%clear A DC DX J11 J22 J33 Qk delta lk ll lm

Newton Raphson Method 2

clear all;
clc;
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
ybus
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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2)*y(3,2)*sin(t(3,2)-
d(3)+d(2))-v(3)^2*y(3,3)*sin(t(3,3));

Enter the number of buses 3

Enter your choice1. impedance, 2. admittance1

Enter the impedance value between 1-2:0.02+0.04j

Enter the impedance value between 1-3:0.01+0.03j

Enter the impedance value between 2-3:0.0125+0.025j

ybus =

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


iter =

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-004 *

0.1465

0.2778

-0.0428

v =

1.0500
0.9717

1.0400

d =

-0.0471

-0.0087

iter =

dc =

1.0e-004 *

-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-005 *

-0.0750

-0.1223

-0.0003

v =

1.0500

0.9717

1.0400

d =

-0.0471

-0.0087

You might also like