Code covered by the BSD License

by

m f (view profile)

.M file for Radial Power Flow

```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;
line=line/Z_base;

Size_line=size(line);

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

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

for i=1:line_number
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

BIBC(:,i-1)=0;
end
end

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

for i=1:line_number
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;
i=1;
telorance=1;

while i<200   % maximum iterations
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;

V_bus_size=size(V_bus);

for i=1:V_bus_size(1,1)
else
end
end

V_bus

```