您好,欢迎访问三七文档
clear;nl=10;%input('请输入支路数:nl=');n=11;%input('请输入节点数:n=');isb=1;%input('请输入平衡母线节点号:isb=');pr=0.00001;%input('请输入误差精度:pr=');B1=[1214.662+44.882i0.001273i10;138.860+35.922i0.001082i10;159.227+28.398i0.000806i10;174.298+17.460i0.000525i10;341.654+54.365i00.9091;562.940+89.380i00.9091;781.723+60.575i00.9091;797.746+31.464i0.000946i11;9101.912+67.220i00.9091;11912.152+49.358i0.000371i10;]B2=[0023123101;077.60+20.926i220002;0146.30+88.304i220002;00220002;087.80+48.511i220002;00220002;0116.96+75.863i220002;00220002;097.46+71.826i220002;00220002;200023123103;]Y=zeros(n);e=zeros(1,n);f=zeros(1,n);V=zeros(1,n);sida=zeros(1,n);S1=zeros(nl);%-------修改部分------------ym=1;SB=100;UB=220;%ym=input('您输入的参数是标么值?(若不是则输入一个不为零的数值)');ifym~=0%SB=input('请输入功率基准值:SB=');%UB=input('请输入电压基准值:UB=');YB=SB./UB./UB;BB1=B1;BB2=B2;fori=1:nlB1(i,3)=B1(i,3)*YB;B1(i,4)=B1(i,4)./YB;enddisp('B1矩阵B1=');disp(B1)fori=1:nB2(i,1)=B2(i,1)./SB;B2(i,2)=B2(i,2)./SB;B2(i,3)=B2(i,3)./UB;B2(i,4)=B2(i,4)./UB;B2(i,5)=B2(i,5)./SB;enddisp('B2矩阵B2=');disp(B2)end%%%---------------------------------------------------fori=1:nl%支路数ifB1(i,6)==0%左节点处于低压侧p=B1(i,1);q=B1(i,2);elsep=B1(i,2);q=B1(i,1);endY(p,q)=Y(p,q)-1./(B1(i,3)*B1(i,5));%非对角元Y(q,p)=Y(p,q);Y(q,q)=Y(q,q)+1./(B1(i,3)*B1(i,5)^2)+B1(i,4)./2;%对角元K侧Y(p,p)=Y(p,p)+1./B1(i,3)+B1(i,4)./2;%对角元1侧end%求导纳矩阵disp('导纳矩阵Y=');disp(Y)%----------------------------------------------------------G=real(Y);B=imag(Y);%分解出导纳阵的实部和虚部fori=1:n%给定各节点初始电压的实部和虚部e(i)=real(B2(i,3));f(i)=imag(B2(i,3));V(i)=B2(i,4);%PV节点电压给定模值endfori=1:n%给定各节点注入功率S(i)=B2(i,1)-B2(i,2);%i节点注入功率SG-SLB(i,i)=B(i,i)+B2(i,5);%i节点无功补偿量end%===================================================================P=real(S);Q=imag(S);ICT1=0;IT2=1;N0=2*n;N=N0+1;a=0;whileIT2~=0IT2=0;a=a+1;fori=1:nifi~=isb%非平衡节点C(i)=0;D(i)=0;forj1=1:nC(i)=C(i)+G(i,j1)*e(j1)-B(i,j1)*f(j1);%Σ(Gij*ej-Bij*fj)D(i)=D(i)+G(i,j1)*f(j1)+B(i,j1)*e(j1);%Σ(Gij*fj+Bij*ej)endP1=C(i)*e(i)+f(i)*D(i);%节点功率P计算eiΣ(Gij*ej-Bij*fj)+fiΣ(Gij*fj+Bij*ej)Q1=C(i)*f(i)-e(i)*D(i);%节点功率Q计算fiΣ(Gij*ej-Bij*fj)-eiΣ(Gij*fj+Bij*ej)%求P',Q'V2=e(i)^2+f(i)^2;%电压模平方%=========以下针对非PV节点来求取功率差及Jacobi矩阵元素=========ifB2(i,6)~=3%非PV节点DP=P(i)-P1;%节点有功功率差DQ=Q(i)-Q1;%节点无功功率差%===============以上为除平衡节点外其它节点的功率计算=================%=================求取Jacobi矩阵===================forj1=1:nifj1~=isb&j1~=i%非平衡节点&非对角元X1=-G(i,j1)*e(i)-B(i,j1)*f(i);%dP/de=-dQ/dfX2=B(i,j1)*e(i)-G(i,j1)*f(i);%dP/df=dQ/deX3=X2;%X2=dp/dfX3=dQ/deX4=-X1;%X1=dP/deX4=dQ/dfp=2*i-1;q=2*j1-1;J(p,q)=X3;J(p,N)=DQ;m=p+1;J(m,q)=X1;J(m,N)=DP;q=q+1;J(p,q)=X4;J(m,q)=X2;elseifj1==i&j1~=isb%非平衡节点&对角元X1=-C(i)-G(i,i)*e(i)-B(i,i)*f(i);%dP/deX2=-D(i)+B(i,i)*e(i)-G(i,i)*f(i);%dP/dfX3=D(i)+B(i,i)*e(i)-G(i,i)*f(i);%dQ/deX4=-C(i)+G(i,i)*e(i)+B(i,i)*f(i);%dQ/dfp=2*i-1;q=2*j1-1;J(p,q)=X3;J(p,N)=DQ;%扩展列△Qm=p+1;J(m,q)=X1;q=q+1;J(p,q)=X4;J(m,N)=DP;%扩展列△PJ(m,q)=X2;endendelse%===============下面是针对PV节点来求取Jacobi矩阵的元素===========DP=P(i)-P1;%PV节点有功误差DV=V(i)^2-V2;%PV节点电压误差forj1=1:nifj1~=isb&j1~=i%非平衡节点&非对角元X1=-G(i,j1)*e(i)-B(i,j1)*f(i);%dP/deX2=B(i,j1)*e(i)-G(i,j1)*f(i);%dP/dfX5=0;X6=0;p=2*i-1;q=2*j1-1;J(p,q)=X5;J(p,N)=DV;m=p+1;J(m,q)=X1;J(m,N)=DP;q=q+1;J(p,q)=X6;J(m,q)=X2;elseifj1==i&j1~=isb%非平衡节点&对角元X1=-C(i)-G(i,i)*e(i)-B(i,i)*f(i);%dP/deX2=-D(i)+B(i,i)*e(i)-G(i,i)*f(i);%dP/dfX5=-2*e(i);X6=-2*f(i);p=2*i-1;q=2*j1-1;J(p,q)=X5;J(p,N)=DV;m=p+1;J(m,q)=X1;J(m,N)=DP;q=q+1;J(p,q)=X6;J(m,q)=X2;endendendendend%=========以上为求雅可比矩阵的各个元素=====================fork=3:N0%N0=2*n(从第三行开始,第一、二行是平衡节点)k1=k+1;N1=N;%N=N0+1即N=2*n+1扩展列△P、△Qfork2=k1:N1%扩展列△P、△QJ(k,k2)=J(k,k2)./J(k,k);%非对角元规格化endJ(k,k)=1;%对角元规格化ifk~=3%不是第三行%============================================================k4=k-1;fork3=3:k4%用k3行从第三行开始到当前行前的k4行消去fork2=k1:N1%k3行后各行下三角元素J(k3,k2)=J(k3,k2)-J(k3,k)*J(k,k2);%消去运算endJ(k3,k)=0;endifk==N0break;end%==========================================fork3=k1:N0fork2=k1:N1J(k3,k2)=J(k3,k2)-J(k3,k)*J(k,k2);%消去运算endJ(k3,k)=0;endelsefork3=k1:N0fork2=k1:N1J(k3,k2)=J(k3,k2)-J(k3,k)*J(k,k2);%消去运算endJ(k3,k)=0;endendend%====上面是用线性变换方式将Jacobi矩阵化成单位矩阵=====fork=3:2:N0-1L=(k+1)./2;e(L)=e(L)-J(k,N);%修改节点电压实部k1=k+1;f(L)=f(L)-J(k1,N);%修改节点电压虚部end%------修改节点电压-----------fork=3:N0DET=abs(J(k,N));ifDET=pr%电压偏差量是否满足要求IT2=IT2+1;%不满足要求的节点数加1endendICT2(a)=IT2;ICT1=ICT1+1;end%用高斯消去法解w=-J*Vdisp('迭代次数:');disp(ICT1);disp('没有达到精度要求的个数:');disp(ICT2);fork=1:nV(k)=sqrt(e(k)^2+f(k)^2);sida(k)=atan(f(k)./e(k))*180./pi;E(k)=e(k)+f(k)*j;end%===============计算各输出量===========================disp('各节点的实际电压标幺值E为(节点号从小到大排列):');disp(E);EE=E*UB;disp(EE);disp('-----------------------------------------------------');disp('各节点的电压大小V为(节点号从小到大排列):');disp(V);VV=V*UB;disp(VV);disp('-----------------------------------------------------');disp('各节点的电压相角sida为(节点号从小到大排列):');disp(sida);forp=1:nC(p)=0;forq=1:nC(p)=C(p)+conj(Y(p,q))*conj(E(q));endS(p)=E(p)*C(p);enddisp('各节点的功率S为(节点号从小到大排列):');disp(S);disp('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');SS=S*SB;disp(SS);disp('-----------------------------------------------------');disp('各条支路的首端功率Si为(顺序同您输入B1时一致):');fori=1:nlp=B1(i,1);q=B1(i,2);ifB1(i,6)==0
本文标题:潮流程序
链接地址:https://www.777doc.com/doc-4362686 .html