matlab 应求PQ分解法进行潮流计算
matlab 应求PQ分解法进行潮流计算
%本程序的功能是利用PQ分解法进行潮流计算
clear
clc
n=input('请输入节点数:n=');
nl=input('请输入支路数:nl=');
isb=input('请输入平衡母线节点号:isb=');
pr=input('请输入误差精度:pr=');
disp('请输入由支路参数形成的矩阵:B1=');
%输入B1
[fname, pname]= uigetfile('*.xls');
file=[pname fname];
x=xlsread(file);
B1=[x(:,1),x(:,2),(x(:,3)+x(:,4)*i),x(:,5)*i,x(:,6),x(:,7)];
disp('请输入由节点参数形成的矩阵:B2=');
%输入B2
[fname, pname]= uigetfile('*.xls');
file=[pname fname];
y=xlsread(file);
B2=[(y(:,1)+y(:,2)*i),(y(:,3)+y(:,4)*i),y(:,5),y(:,6),y(:,7),y(:,8)];
disp('请输入由节点号及其对地阻抗形成的矩阵:X=');
%输入X
[fname, pname]= uigetfile('*.xls');
file=[pname fname];
z=xlsread(file);
X=z;
na=input('请输入PQ节点数na=');
Y=zeros(n);YI=zeros(n);e=zeros(1,n);f=zeros(1,n);V=zeros(1,n);O=zeros(1,n);
for i=1:n
if X(i,2)~=0;
p=X(i,1);
Y(p,p)=1./X(i,2);
end
end
for i=1:nl
if B1(i,6)==0
p=B1(i,1);q=B1(i,2);
else p=B1(i,2);q=B1(i,1);
end
Y(p,q)=Y(p,q)-1./(B1(i,3)*B1(i,5));
YI(p,q)=YI(p,q)-1./B1(i,3);
Y(q,p)=Y(p,q);
YI(q,p)=YI(p,q);
Y(q,q)=Y(q,q)+1./(B1(i,3)*B1(i,5)^2)+B1(i,4)./2;
YI(q,q)=YI(q,q)+1./B1(i,3);
Y(p,p)=Y(p,p)+1./B1(i,3)+B1(i,4)./2;
YI(p,p)=YI(p,p)+1./B1(i,3);
end %求导纳矩阵
G=real(Y);B=imag(YI);BI=imag(Y);
for i=1:n
S(i)=B2(i,1)-B2(i,2);
BI(i,i)=BI(i,i)+B2(i,5);
end
P=real(S);Q=imag(S);
for i=1:n
e(i)=real(B2(i,3));
f(i)=imag(B2(i,3));
V(i)=B2(i,4);
end
for i=1:n
if B2(i,6)==2
V(i)=sqrt(e(i)^2+f(i)^2);
O(i)=atan(f(i)./e(i));
end
end
for i=2:n
if i==n
B(i,i)=1./B(i,i);
else IC1=i+1;
for j1=IC1:n
B(i,j1)=B(i,j1)./B(i,i);
end
B(i,i)=1./B(i,i);
for k=i+1:n
for j1=i+1:n
B(k,j1)=B(k,j1)-B(k,i)*B(i,j1);
end
end
end
end
p=0;q=0;
for i=1:n
if B2(i,6)==2
p=p+1;k=0;
for j1=1:n
if B2(j1,6)==2
k=k+1;
A(p,k)=BI(i,j1);
end
end
end
end
for i=1:na
if i==na
A(i,i)=1./A(i,i);
else k=i+1;
for j1=k:na
A(i,j1)=A(i,j1)./A(i,i);
end
A(i,i)=1./A(i,i);
for k=i+1:na
for j1=i+1:na
A(k,j1)=A(k,j1)-A(k,i)*A(i,j1);
end
end
end
end
ICT2=1;ICT1=0;kp=1;kq=1;K=1;DET=0;ICT3=1;
while ICT2~=0|ICT3~=0
ICT2=0;ICT3=0;
for i=1:n
if i~=isb
C(i)=0;
for k=1:n
C(i)=C(i)+V(k)*(G(i,k)*cos(O(i)-O(k))+B