Radial Power Flow

by

 

.M file for Radial Power Flow

radial_Power_flow.m
clc
clear all

% line=[3 0 0 0 0 0
%       0 5 0 0 0 0
%       0 0 6 0 8 0
%       0 0 0 4 0 0
%       0 0 0 0 0 0
%       0 0 0 0 0 7];
% 
% load_power=[0 7 0 2 0 8 1]; %P+jQ

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

line=[1 0 0 0 0 0 0 0
      0 5 0 0 0 0 4 0
      0 0 6 0 8 0 0 0
      0 0 0 4 0 0 0 0
      0 0 0 0 0 0 0 0
      0 0 0 0 0 7 0 0
      0 0 0 0 0 0 0 0
      0 0 0 0 0 0 0 4];

load_power=[0 7 0 2 3 0 4 0 2];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
V_base=30;
S_base=30;
Z_base=V_base^2/S_base;
load_power=load_power/S_base;
line=line/Z_base;

Size_line=size(line);
Size_load_power=size(load_power);

[line_number,xxx]=size(find(line~= 0));
[xxx,load_power_number]=size(find(load_power~= 0));

%%%%%%%%  for BIBC   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

BIBC=zeros(line_number,Size_load_power(1,2)-1);

for i=1:line_number
    for j=1:Size_load_power(1,2)-1
        if line(i,j)~= 0
            B=j;
            if i==1 && j==1
                BIBC(i,j)=1;
            else
                BIBC(:,j)=BIBC(:,i-1);
                BIBC(B,j)=1;
            end
        end
    end
end


for i=2:Size_load_power(1,2)
    
    if load_power(1,i)== 0
        BIBC(:,i-1)=0;
    end
end

%%%%%%%%      for BCBV      %%%%%%%%%%%%%%%%%%%%%%%%

BCBV=zeros(line_number,Size_load_power(1,2)-1);

            
for i=1:line_number
    for j=1:Size_load_power(1,2)-1
        if line(i,j)~= 0
            B=j;
            if i==1 && j==1
                BCBV(i,j)=line(i,j);
            else
                BCBV(j,:)=BCBV(i-1,:);
                BCBV(j,j)=line(i,j);
            end
        end
    end
end
 
% %%%%%%%%%%%%%   main  load flow        %%%%%%%%%%%%%%%% 
    
 DLF=BCBV*BIBC;
 V1=ones(Size_load_power(1,2)-1,1);
 V_bus=ones(Size_load_power(1,2)-1,1);
 I=zeros(Size_load_power(1,2)-1,1);
 Iaa=zeros(Size_load_power(1,2)-1,1);
 i=1;
 telorance=1;
 
 
 while i<200   % maximum iterations
     for j=1:Size_load_power(1,2)-1
         I(j,1)=conj(load_power(1,j+1)/V_bus(j,1));
     end
     I_test(:,i)=I;
     V_bus= V1-(DLF*I);
     V_test(:,i)=V_bus;
     
     
     if i<=1
         telorance= 1;   % convergence condition
         
     else
         telorance= abs(abs(I_test(line_number,i))-abs(I_test(line_number,i-1)));
         fprintf('itr %g     V_bus= %g     I_i=%g     I_i-1=%g      tel=%g  \n',i,V_bus(line_number,1),abs(I_test(line_number,i)),abs(I_test(line_number,i-1)),telorance)
     
     end
     if abs(telorance) <= 1e-5
         break
     end
        i=i+1;
 end
 
 V_bus_size=size(V_bus);
 v_bus_shift=zeros(V_bus_size(1,1)+1,1);
 v_bus_shift(1,1)=1;
 
for i=2: V_bus_size(1,1)+1
    v_bus_shift(i,1)=V_bus(i-1,1);
end

 V_bus=v_bus_shift;
 
%%%%%%  calculate the loads Impedance)

V_bus_size=size(V_bus);
Z_loads=zeros(Size_load_power(1,2),1);

for i=1:V_bus_size(1,1)
    if load_power(1,i) ~= 0
        Z_loads(i,1)=(V_bus(i,1))^2/load_power(1,i);
    else
        Z_loads(i,1)=0;
    end
end

V_bus
 
 
    
    
    
    
    
    
    






Contact us