www.pudn.com > powerflow.rar > powerflow.m, change:2013-07-06,size:2948b


function [U,ploss]=powerflow() 
n=33; 
b=32; 
Sb=10;       %基准功率 
Ub=12.66;    %基准电压 
Zb=Ub^2/Sb;  %基准阻抗 
 
%输入系统参数 
Z=[ 1, 0, 1,0.0922/Zb+0.0470i/Zb,0.100/Sb+0.060i/Sb 
    2, 1, 2,0.4930/Zb+0.2511i/Zb,0.090/Sb+0.040i/Sb 
    3, 2, 3,0.3660/Zb+0.1864i/Zb,0.120/Sb+0.080i/Sb 
    4, 3, 4,0.3811/Zb+0.1941i/Zb,0.060/Sb+0.030i/Sb 
    5, 4, 5,0.8190/Zb+0.7070i/Zb,0.060/Sb+0.020i/Sb 
    6, 5, 6,0.1872/Zb+0.6188i/Zb,0.200/Sb+0.100i/Sb 
    7, 6, 7,0.7114/Zb+0.2351i/Zb,0.200/Sb+0.100i/Sb 
    8, 7, 8,1.0300/Zb+0.7400i/Zb,0.060/Sb+0.020i/Sb 
    9, 8, 9,1.0440/Zb+0.7400i/Zb,0.060/Sb+0.020i/Sb 
    10, 9,10,0.1966/Zb+0.0650i/Zb,0.045/Sb+0.030i/Sb 
    11,10,11,0.3744/Zb+0.1238i/Zb,0.060/Sb+0.035i/Sb 
    12,11,12,1.4680/Zb+1.1550i/Zb,0.060/Sb+0.035i/Sb 
    13,12,13,0.5416/Zb+0.7129i/Zb,0.120/Sb+0.080i/Sb 
    14,13,14,0.5910/Zb+0.5260i/Zb,0.060/Sb+0.010i/Sb 
    15,14,15,0.7463/Zb+0.5450i/Zb,0.060/Sb+0.020i/Sb 
    16,15,16,1.2890/Zb+1.7210i/Zb,0.060/Sb+0.020i/Sb 
    17,16,17,0.7320/Zb+0.5740i/Zb,0.090/Sb+0.040i/Sb 
    18, 1,18,0.1640/Zb+0.1565i/Zb,0.090/Sb+0.040i/Sb 
    19,18,19,1.5042/Zb+1.3554i/Zb,0.090/Sb+0.040i/Sb 
    20,19,20,0.4095/Zb+0.4784i/Zb,0.090/Sb+0.040i/Sb 
    21,20,21,0.7089/Zb+0.9373i/Zb,0.090/Sb+0.040i/Sb 
    22, 2,22,0.4512/Zb+0.3083i/Zb,0.090/Sb+0.050i/Sb 
    23,22,23,0.8980/Zb+0.7091i/Zb,0.420/Sb+0.200i/Sb 
    24,23,24,0.8960/Zb+0.7011i/Zb,0.420/Sb+0.200i/Sb 
    25, 5,25,0.2030/Zb+0.1034i/Zb,0.060/Sb+0.025i/Sb 
    26,25,26,0.2842/Zb+0.1447i/Zb,0.060/Sb+0.025i/Sb 
    27,26,27,1.0590/Zb+0.9337i/Zb,0.060/Sb+0.020i/Sb 
    28,27,28,0.8042/Zb+0.7006i/Zb,0.120/Sb+0.070i/Sb 
    29,28,29,0.5075/Zb+0.2585i/Zb,0.200/Sb+0.600i/Sb 
    30,29,30,0.9744/Zb+0.9630i/Zb,0.150/Sb+0.070i/Sb 
    31,30,31,0.3105/Zb+0.3619i/Zb,0.210/Sb+0.100i/Sb 
    32,31,32,0.3410/Zb+0.5302i/Zb,0.060/Sb+0.040i/Sb];  
 
v=ones(1,n);   %初始化节点电压 
k=0; 
L1=0; 
while  k<10&&L1<1     %收敛条件 
    v_before=v; 
    %计算节点注入电流,b=32为系统支路数 
    I=zeros(b,1);   %生成一个b行1列的零矩阵 
    for h=1:b 
        I(h)=conj(Z(h,5)/v(1,h+1)); %求节点注入电流,conj为求共轭 
    end 
    J=zeros(b,1); 
    J=J+I;    %支路电流,J矩阵中存储的是各节点注入电流,J有32行1列 
    for h=b-1:-1:1 
        nn=Z(h,3);   %取系统中末端节点编号 
        for j=b:-1:1 
            if Z(j,2)==nn    %说明他们之间首末端点是相连的 
                J(h)=J(h)+J(j); 
            end 
        end 
    end 
   %回推节点电压 
    for h=1:b 
        m=Z(h,2);mm=Z(h,3); 
        v(1,mm+1)=v(1,m+1)-Z(h,4)*J(h); 
    end 
    %收敛条件 
    for h=1:b 
        dat_v(h)=abs(v(h))-abs(v_before(h)); 
    end 
    if max(abs(dat_v))<1.0e-4 
        L1=1;    %不能用dat_v(i)就指最后的元素第i个 
    end 
    k=k+1; 
end 
 
%计算网损 
ws=zeros(b,1); 
for i=1:1:b; 
    ws(i,1)=J(i,1)*conj(J(i,1))*real(Z(i,4))*Sb; 
end 
ploss=zeros(n,1); 
ploss=sum(ws); 
 
U=zeros(n,1); 
for i=1:n; 
    U(i)=real(v(i)); 
end 
ploss,U 
end