Vous êtes sur la page 1sur 6

# 10/5/11 1:21 AM

H:\rs_nr.m

1 of 6

## function [Out] = rs_nr(ybus,k,itt,error)

%RS_NR Summary: Written By: Ravi sharma , M.Tech(PS), DCRUST
%This program solve load flow problem using Newton-Rapson
% Explanation:
%This program return the injected power(Pi,Qi) and V<s output of N-Bus system
%with GS method.Program required ravi_sybusm() function for ybus formation.
% Description:
%Function rs_gs(a,b,c,d) required four input argument where 'a' is a variable
%which contain 'ybus'matrix,'b' contain the no. of bus of the system,'c' contain no. of
itteration,
%and 'd'will define the max error to converge itteration.
%# IF 'a'input is entered zero then it will form a YBUS using singular
%transformation with function "ravi_sybusm()".
%# 'b' must not be less then or equal to zero & should meet YBUS parameter.
%# 'c' Default will be taken 'infinite', if wrong or invalid entry found.
%# 'd' Default will be taken 0.0001, if wrong or invalid entry found.
%Function rs_gs() intake data for SLACK, PV & PQ buses in PU irrespective to their
assumed sequence.
%This program automaticaly check for different kind of bus as per input data.
%# Data will be Entered in form of a vector matrix of one row of [P,Q,V,\$].
%Function rs_gs() gives the output in form of a matrix of 4xb where b is
%No. of buses as:
% \1
2
3
4
5
....b
% V|
% \$|
% P|
% Q|
%# if PV bus reactive power become <=Qmin or >=Qmax then bus will be treated as
% PQ bus for further calculation (with Q= Qmin or Qmax).
%
%
%
if((nargin<3)||(k<=0))
disp('Please enter all argument: (Ybus,no.of buses,error) !');
return;
elseif ybus<=0
ybus=ravi_sybusm(k);
end
P=zeros(1,k);
Q=zeros(1,k);
Qmin=zeros(1,k);
Qmax=zeros(1,k);
V=zeros(1,k);
Del=zeros(1,k);
z=zeros(k,4);
typ=zeros(1,k);
if 0.1<error<=0
error=0.0001;
end
if itt<=1
itt=inf;

10/5/11 1:21 AM

H:\rs_nr.m

end
for i=1:k
fprintf('Enter the given value Pi Qi Vi and \$(radian) for bus no %d',i);
z(i,:)=input('=>> ');
end
cs =0;
cpq=0;
for i=1:k
if ((z(i,1)==0)&&(z(i,2)==0))
typ(1,i)=1;
cs=cs+1;
end
if ((z(i,1)~=0)&&(z(i,2)~=0))
typ(1,i)=3;
cpq=cpq+1;
end
P(1,i)=z(i,1);
Q(1,i)=z(i,2);
V(1,i)=z(i,3);
if (z(i,3)==0);
V(1,i)=1;
end
Del(1,i)=z(i,4);
end
for i=1:k
if typ(1,i)==0
fprintf('Enter the value of Qmin for BUS %d',i);
Qmin(1,i)=input('=>> ');
fprintf('Enter the value of Qmax for BUS %d',i);
Qmax(1,i)=input('=>> ');
end
end
cpv=k-cs-cpq;
col=2*k-2*cs-cpv;
jack=zeros(col,col);
PQi=zeros(col,1);
VDi=zeros(col,1);
PQ=zeros(col,1);
it=1;err=1;
while (err>error)&&(it<=itt)
it=it+1;
h1=1;
for pi=1:k
if h1<=(cpq+cpv)
if(typ(1,pi)~=1)
PQi(h1,1)=pi;
h1=h1+1;
end
end
end
for pi=1:k

2 of 6

10/5/11 1:21 AM

H:\rs_nr.m

if h1>(cpq+cpv)
if typ(1,pi)==3
PQi(h1,1)=pi;
h1=h1+1;
end
end
end
h1=1;
for pi=1:k
if h1<=cpq
if(typ(1,pi)==3)
VDi(h1,1)=pi;
h1=h1+1;
end
end
end
for pi=1:k
if h1>cpq
if typ(1,pi)~=1
VDi(h1,1)=pi;
h1=h1+1;
end
end
end
for x5=1:col
if x5<=(cpq+cpv)
PQ(x5,1)= P(1,PQi(x5,1))-real(S(PQi(x5,1)));
else
PQ(x5,1)= Q(1,PQi(x5,1))+imag(S(PQi(x5,1)));
end
err=abs(max(PQ));
end
VD=eljacobian()\PQ;
for x1=1:col
if x1<=cpq
V(1,VDi(x1,1))=V(1,VDi(x1,1))+VD(x1,1);
elseif x1>=cpq
Del(1,VDi(x1,1))=Del(1,VDi(x1,1))+VD(x1,1);
end
end
for xt=1:k
if typ(1,xt)==0
Q(1,xt)=-imag(S(xt));
if Q(1,xt)<=Qmin(1,xt)
typ(1,xt)=3;
Q(1,xt)=Qmin(1,xt);
break;
elseif Q(1,xt)>=Qmax(1,xt)
Q(1,xt)=Qmax(1,xt);
typ(1,xt)=3;
break;
end

3 of 6

10/5/11 1:21 AM

H:\rs_nr.m
end

end
end
aslack();
function [] = aslack()
for xs=1:k
if typ(1,xs)==1
sumx=0;
for ys=1:k
sumx=sumx+(V(1,ys)*exp(1j*Del(1,ys)))*ybus(xs,ys);
end
P(1,xs)= real(V(1,xs)*exp(-1j*Del(1,xs))*sumx);
Q(1,xs)= -imag(V(1,xs)*exp(-1j*Del(1,xs))*sumx);
end
end
end
Out(3,:)=P;
Out(4,:)=Q;
Out(1,:)=V;
Out(2,:)=Del;
function [op] = S(x6)
sumx=0;
for y6=1:k
sumx=sumx+V(1,y6)*exp(1j*Del(1,y6))*ybus(x6,y6);
end
op=V(1,x6)*exp(-1j*Del(1,x6))*sumx;
end
%-----------------------jacobian calculation---------------------------function [op] = eljacobian ()
for r=1:col
for c=1:col
if(r<=(cpq+cpv))&&(c<=cpq)
jack(r,c)=e13(PQi(r,1),VDi(c,1));
elseif(r<=(cpq+cpv))&&(c>=cpq)
jack(r,c)=e57(PQi(r,1),VDi(c,1));
elseif(r>=(cpq+cpv))&&(c<=cpq)
jack(r,c)=e24(PQi(r,1),VDi(c,1));
elseif(r>=(cpq+cpv))&&(c>=cpq)
jack(r,c)=e68(PQi(r,1),VDi(c,1));
end
end
end
op=jack;
end
%-----------------------------xxx-----------------------------------%---------------------Derivated Equation for NR---------------------function [PbyV]= e13(bus,vol)
if bus~=vol
PbyV=real(conj(V(1,bus))*ybus(bus,vol).*exp(1j*angle(V(1,vol))));

4 of 6

10/5/11 1:21 AM

H:\rs_nr.m

else
sump=0;
for x8=1:k
if x8~=bus
sump=sump+ybus(bus,x8)*V(1,x8).*exp(-1j*angle(V(1,bus)));
end
end
PbyV=real(sump+2*abs(V(1,bus))*ybus(bus,bus));
end
end
function [QbyV]= e24(bus,vol)
if bus~=vol
QbyV=-imag(conj(V(1,bus))*ybus(bus,vol).*exp(1j*angle(V(1,vol))));
else
sump=0;
for x9=1:k
if x9~=bus
sump=sump+ybus(bus,x9)*V(1,x9).*exp(-1j*angle(V(1,bus)));
end
end
QbyV=-imag(sump+2*abs(V(1,bus))*ybus(bus,bus));
end
end
function [PbyD]= e57(bus,D)
if bus~=D
PbyD=real(1j*conj(V(1,bus))*V(1,D)*ybus(bus,D));
else
sump=0;
for x10=1:k
if x10~=bus
sump=sump+ybus(bus,x10)*V(1,x10);
end
end
PbyD=real(-1j*sump*conj(V(1,bus)));
end
end
function [QbyD]= e68(bus,D)
if bus~=D
QbyD=-imag(1j*conj(V(1,bus))*V(1,D)*ybus(bus,D));
else
sump=0;
for x11=1:k
if x11~=bus
sump=sump+ybus(bus,x11)*V(1,x11);
end
end
QbyD=-imag(-1j*sump*conj(V(1,bus)));
end
end
%--------------------------------xxx-------------------------------------end

5 of 6

10/5/11 1:21 AM

H:\rs_nr.m

%--------------------------------END OF PROGRAM---------------------------

6 of 6