Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Nraphson M

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

PROGRAM 4

clc;
clear all;
n=input('No. of buses=');
l=input('No. of lines=');
s=input('Enter 1 if Impedence or 2 if Admittance :');
for i=i:1
a=input('starting bus:');
b=input('ending bus:');
t=input('Impedence/Admittance value:');

if s==1
y(a,b)=1/t;
else
y(a,b)=t;
end
y(b,a)=y(a,b);
end
ybus=zeros(n,n);
for i=1:n
for j=1:n
if i==j
for k=i:n
ybus(i,j)=ybus(i,j)+y(i,k);
end
else
ybus(i,j)=y(i,j);
end
ybus(j,i)=ybus(i,j);
end
end
disp(ybus);
y1=zeros(n,n);
y2=zeros(n,n);
y1=abs(ybus);
y2=angle(ybus);
disp(y1);
disp(y2);
v=zeros(1,n);
d=zeros(1,n);
pspec=zeros(1,n);
qspec=zeros(1,n);
for i=1:n
v(i)=input('Enter voltage value:');
d(i)=input('Enter degree value:');
pspec(i)=input('Enter pspec value :');
qspec(i)=input('Enter qspec value:');
end
disp(v);
disp(d);
pcal=zeros(n,1);
qcal=zeros(n,1);
for i=2:n
for j=1:n
pcal(i)=pcal(i)+(v(i)*y1(i,j)*cos(y2(i,j)+d(j)-d(i)));
qcal(i)=qcal(i)+((-1)*(v(i)*y(i,j)*v(j)+d(j)-d(i)));
end
end
disp(pcal);
disp(qcal);
dp=zeros(n,1);
dq=zeros(n,1);
for i=2:n
dp(i)=pspec(i)-pcal;
dp(i)=qspec(i)-qcal;
end
disp(dp);
disp(dq);
D=zeros(n,1);
D=[dp(2);dp(3);dq(3)];
disp(D);
J1=zeros(n,n);
for i =2:n
for j = 1:n
if j~=1
J(i,i)=(v(i)*y(i,j)*v(j)*sin((y2(i,j))+d(j)-d(i)));
for j=2:n
J1(i,j)=-(v(i)*y1(i,j)*v(j)*sin((y2(i,j))+d(j)-d(i)));
end
end
end
end
disp(J1);
J1(1,:)=[];
J1(:,1)=[];
disp(J1);
J2=zeros(n,n);
for i=3:n
for i=1:n
if j~=i
a1=0;
a2=0;
a1=a1+(v(j)*y1(i,j)*cos((y2(i,j))+d(j)-d(i)));
a2=a2+(2*v(i)^2)*y1(i.j)*cos((y2(i,j)+d(j)-d(i)));
J2(i,j)=a1+a2;
for i=2:n
for j=3:n
J2(i,j)=(v(i)*v(j)*y1(i,j)*cos((y2(i,j))+d(j)-d(i)));
end
end
end
end
end
disp(J2);
J2(:,1)=[];
J2(1,:)=[];
J2(:,1)=[];
disp(J2);
J3=zeros(n,n);
for i=2:n
for j=1:n
if j~=1
J3(i,j)=(v(i)*y1(i,j)*v(j)*cos(y2(i,j)+d(j)-d(i)));
end
for j=2:n
J3(i,j)=-(v(i)*y1(i,j)*v(i,j)*v(j)*cos(y2(i,j)+d(j)-d(i)));
end
end
end
J3(1,:)=[];
J3(:,1)=[];
J3(1,:)=[];
disp(J3);
J4=zeros(n,n);
for i=3:n
for j=3:n
b1=0;
b1=b1-(1*(2*v(i)^2)*y1(i,i)*sin(y2(i,i)+d(j)-d(i)));
b2=0;
for i=3:n
for j=1:n
if j~=i
b2=b2-(1*v(i)*v(j)*sin(y2(i,j)+d(j)-d(i)));
end
j4(i,i)=b1+b2;
end
end
end
end
disp(J4);
J4(1,:)=[];
J4(:,1)=[];
J4(1,:)=[];
disp(J4);
J=zeros(n,n);
J=[J1 J2;J3 J4];
disp(J);
R=zeros(n,n);
R=inv(J);
disp(R)
E=zeros(n,1);
E=R*D;
disp(E);
dln=zeros();
for i=2:n
dln(1)=0;
dln(i)=d(i)+E(i-1);
end
disp(dln);
vnew=zeros();
for i=1:n
vnew(i)=v(i);
end
for i=3:n
vnew(i)=v(i)+v(i)*E(i,1);
end
disp(vnew);
vnew1=zeros();
for i=1:n
vnew1(i)=vnew(i)*(cos(dln(i))+(1j*sin(dln(i))));
end
Voltage=['Vnew = ',num2str(vnew1)];
disp(Voltage);

You might also like