Вы находитесь на странице: 1из 3

%INPUT -------------------------------------------------------------------%

clc
zdata = [ 1 2 0.01008 0.05040 0.1025;
1 3 0.00744 0.03720 0.0775;
2 4 0.00744 0.03720 0.0775;
3 4 0.01272 0.06360 0.1275 ];
ydata = [ 1 0 0 50 30.99 1 0;
2 0 0 170 105.35 1 0;
3 0 0 200 123.94 1 0;
4 0 0 250 140.00 1 0 ];

%DATA---------------------------------------------------------------------%
%function [Y] = ybus1(zdata)
nl = zdata(:,1) ; nr = zdata(:,2) ; R = zdata(:,3) ; X = zdata(:,4);
A = zdata(:,5);
%function [X] = Jaco(ydata)
Bus = ydata(:,1); Pg = ydata(:,2); Qg = ydata(:,3); Pd = ydata(:,4);
Qd = ydata(:,5); V = ydata(:,6); Delta = ydata(:,7);
nbr = length(zdata(:,1)) ; nbus = max(max(nl),max(nr));
Z = R + j*X; %Series impedance
SY = j*A ./ 2; %Shunt admittance
y = ones(nbr,1)./Z; %Series admittance
Pd = Pd / 100;
Qd = Qd / 100;
Y = zeros(nbus,nbus);
J1 = zeros(nbus-1,nbus-1);
J2 = zeros(nbus-1,nbus-1);
J3 = zeros(nbus-1,nbus-1);
J4 = zeros(nbus-1,nbus-1);
P = zeros(nbus-1,1);
Q = zeros(nbus-1,1);
%CODE---------------------------------------------------------------------%
Error = 1;
Count = 1;
for b = 1:2
%while (Error > 1e-1)
fprintf('Iteration %d',Count)
%BUS ADMITTANCE-----------------------------------------------------------%
for i = 1 : nbr; %Formation of the off diagonal elements
if nl(i) > 0 & nr(i) > 0
Y(nl(i),nr(i)) = Y(nl(i),nr(i)) - y(i);
Y(nr(i),nl(i)) = Y(nl(i),nr(i));
end
end
for n = 1:nbus %Formation of the diagonal elements
for i = 1:nbr
if nl(i) == n | nr(i) == n
Y(n,n) = Y(n,n) + y(i) + SY(i);
else, end
end
end
Y = ybus1(zdata); %Bus admittance matrix
%JACOBIAN MATRIX----------------------------------------------------------%
for j = 1 : nbus-1
for k = 1 : nbus-1
if j ~= k %Formation of off diagonal elements
i = j + 1;
n = k + 1;
J1(j,k) = -abs(Y(i,n))*V(i)*V(n)*sin(angle(Y(i,n))+Delta(n)-Delta(i));
J2(j,k) = abs(Y(i,n))*V(i)*cos(angle(Y(i,n))+Delta(n)-Delta(i));
J3(j,k) = -abs(Y(i,n))*V(i)*V(n)*cos(angle(Y(i,n))+Delta(n)-Delta(i));
J4(j,k) = -abs(Y(i,n))*V(i)*sin(angle(Y(i,n))+Delta(n)-Delta(i));
else if j == k %Formation of diagonal elements
i = j + 1;
for n = 1:nbus
if i ~= n
J1(j,k) = J1(j,k)+(abs(Y(i,n))*V(i)*V(n)*sin(angle(Y(i,n))+Delta(n)-Delta(i)
));
J2(j,k) = J2(j,k)+(abs(Y(i,n))*V(n)*cos(angle(Y(i,n))+Delta(n)-Delta(i)));
J3(j,k) = J3(j,k)+(abs(Y(i,n))*V(i)*V(n)*cos(angle(Y(i,n))+Delta(n)-Delta(i)
));
J4(j,k) = J4(j,k)+(-abs(Y(i,n))*V(n)*sin(angle(Y(i,n))+Delta(n)-Delta(i)));

else if i == n
J2(j,k) = J2(j,k)+(2*abs(Y(i,n))*V(i)*cos(angle(Y(i,n))));
J4(j,k) = J4(j,k)+(-2*abs(Y(i,n))*V(i)*sin(angle(Y(i,n))));
end
end
end
end
end
end
end
J = [J1 J2;J3 J4] %Jacobian matrix
%DERIVATIVE OF P&Q--------------------------------------------------------%
for j = 1 : nbus-1
i = j + 1;
P(j) = Pg(i)-Pd(i)-( abs(Y(i,i))*V(i)*V(i)*cos(angle(Y(i,i))));
Q(j) = Qg(i)-Qd(i)-(-abs(Y(i,i))*V(i)*V(i)*sin(angle(Y(i,i))));
for k = 1 : nbus
if i ~= k
P(j) = P(j)-( abs(Y(i,k))*V(i)*V(k)*cos(angle(Y(i,k))+Delta(k)-Delta(i)));
Q(j) = Q(j)-(-abs(Y(i,k))*V(i)*V(k)*sin(angle(Y(i,k))+Delta(k)-Delta(i)));
end
end
end
M = [P ; Q] %Mismatch matrix
U = inv(J)*M; %Voltges and angles
%CORRECTION TO VALUES DELTA AND V-----------------------------------------%
for j = 1 : nbus-1
i = j + 1;
k = j + 3;
Delta(i) = Delta(i) + U(j);
V(i) = V(i) + U(k);
end
V = V
Delta = Delta
Solution = [Delta ; V]; %Solution
Error = max(abs(M));
Count = Count + 1;
end