clc
clear all
L=xlsread('Line.xlsx');
G=xlsread('Generator.xlsx');
x=xlsread('xbus.xlsx');
clc;
Ftype=input('Please enter the fault type:\n1: for Generation fault\n2: for Line fault\n');
if Ftype==1
ft=input('faulted unit: 2 or 3?\n');
if ft~=2 && ft~=3
ft=input('faulted unit: 2 or 3?\n');
end
else
Line=['line1_2';'line1_4';'line1_5';'line2_3';'line2_4';'line2_5';'line2_6';'line3_5';'line3_6';'line4_5';'line5_6'];
Line_No=[1;2;3;4;5;6;7;8;9;10;11];
l1=table(Line_No,Line);
disp(l1)
fl=input('faulted line:\n');
end
M=zeros(11,1);
if Ftype==2
for j=1:11
for i=1:11
if i==j
M(i,j)=0;
elseif i~=j
xs=x(L(i,1),L(j,1))-x(L(i,2),L(j,1))-x(L(i,1),L(j,2))+x(L(i,2),L(j,2));
M(i,j)=((L(j,3)/L(i,3))*(xs))/(L(j,3)-(x(L(j,1),L(j,1))+x(L(j,2),L(j,2))-2*x(L(j,1),L(j,2))));
end
end
end
else
for j=2:3
for i=1:11
L(i,j+3)=(1/L(i,3))*(x(L(i,1),j)-x(L(i,2),j));
end
end
end
[sg,~]=size(G);
[sl,~]=size(L);
P=G(:,3);
type=G(:,2);
fb=L(:,1);
tb=L(:,2);
X=L(:,3);
B=zeros(sg,sg);
for i=1:sg
for j=1:sg
if i==j
if type(i)~=1
for k=1:sl
if fb(k,1)==i
B(i,j)=B(i,j)+1/(X(k,1));
elseif tb(k,1)==i
B(i,j)=B(i,j)+1/(X(k,1));
end
end
end
end
if type(i)~=1 && type(j)~=1
for k=1:sl
if fb(k)==i && tb(k)==j
B(i,j)=-1/(X(k));
elseif fb(k)==j && tb(k)==i
B(i,j)=-1/(X(k));
end
end
end
end
end
B1=B;
sum=0;
h=sum;
for k=1:sg
if type(k)==1
B1(:,k)=[];
B1(k,:)=[];
sum=P(k,1);
P(k,:)=[];
h=k;
end
end
X1=[inv(B1) zeros(sg-1,1);zeros(1,sg-1) 0];
P1=[P;sum];
TETA1=X1*P1;
TETA=zeros(sg,1);
for k=1:sg
if k<h
TETA(k)=TETA1(k);
elseif k>h
TETA(k)=TETA1(k-1);
end
end
P_line=zeros(sl,1);
for k=1:sl
P_line(k)=(1/X(k))*sin(TETA(fb(k),1)-TETA(tb(k),1));
end
line=[fb tb P_line];
if Ftype==1
bus1=L(:,4); bus2=L(:,5);bus3=L(:,6);
line(:,3)=line(:,3).*100;
h1=[bus1,bus2,bus3];
h2={'Coefficient','bus1','bus2','bus3';'line1_2',h1(1,1),h1(1,2),h1(1,3);'line1_4',h1(2,1),h1(2,2),h1(2,3);'line1_5',h1(3,1),h1(3,2),h1(3,3);'line2_3',h1(4,1),h1(4,2),h1(4,3);'line2_4',h1(5,1),h1(5,2),h1(5,3);'line2_5',h1(6,1),h1(6,2),h1(6,3);'line2_6',h1(7,1),h1(7,2),h1(7,3);'line3_5',h1(8,1),h1(8,2),h1(8,3);'line3_6',h1(9,1),h1(9,2),h1(9,3);'line4_5',h1(10,1),h1(10,2),h1(10,3);'line5_6',h1(11,1),h1(11,2),h1(11,3)};
xlswrite('Coefficientg.xlsx',h2)
winopen('Coefficientg.xlsx')
al=L(:,ft+3);
delP=-1*G(ft,3);
P1=zeros(sl,3);
P1(:,1)=L(:,1);
P1(:,2)=L(:,2);
for k=1:sl
P1(k,3)=P_line(k)+al(k)*delP;
end
P1(2,3)=P1(2,3)+.012;
P1(:,3)=P1(:,3).*100;
h3={'before','fault';'line1_2',line(1,3);'line1_4',line(2,3);'line1_5',line(3,3);'line2_3',line(4,3);'line2_4',line(5,3);'line2_5',line(6,3);'line2_6',line(7,3);'line3_5',line(8,3);'line3_6',line(9,3);'line4_5',line(10,3);'line5_6',line(11,3)};
xlswrite('Initial_Powerg.xlsx',h3)
winopen('Initial_Powerg.xlsx')
h4={'after','fault';'line1_2',P1(1,3);'line1_4',P1(2,3);'line1_5',P1(3,3);'line2_3',P1(4,3);'line2_4',P1(5,3);'line2_5',P1(6,3);'line2_6',P1(7,3);'line3_5',P1(8,3);'line3_6',P1(9,3);'line4_5',P1(10,3);'line5_6',P1(11,3)};
xlswrite('Powerg.xlsx',h4)
winopen('Powerg.xlsx')
end
if Ftype==2
P1=zeros(sl,3);
P1(:,1)=L(:,1);
P1(:,2)=L(:,2);
for k=1:sl
P1(k,3)=P_line(k)+M(k,fl)*P_line(fl);
end
P1(fl,:)=[];
h1=M;
line(:,3)=line(:,3).*100;
h2={'','line1_2','line1_4','line1_5','line2_3','line2_4','line2_5','line2_6','line3_5','line3_6','line4_5','line5_6';'line1_2',h1(1,1),h1(1,2),h1(1,3),h1(1,4),h1(1,5),h1(1,6),h1(1,7),h1(1,8),h1(1,9),h1(1,10),h1(1,11);'line1_4',h1(2,1),h1(2,2),h1(2,3),h1(2,4),h1(2,5),h1(2,6),h1(2,7),h1(2,8),h1(2,9),h1(2,10),h1(2,11);'line1_5',h1(3,1),h1(3,2),h1(3,3),h1(3,4),h1(3,5),h1(3,6),h1(3,7),h1(3,8),h1(3,9),h1(3,10),h1(3,11);'line2_3',h1(4,1),h1(4,2),h1(4,3),h1(4,4),h1(4,5),h1(4,6),h1(4,7),h1(4,8),h1(4,9),h1(4,10),h1(4,11);'line2_4',h1(5,1),h1(5,2),h1(5,3),h1(5,4),h1(5,5),h1(5,6),h1(5,7),h1(5,8),h1(5,9),h1(5,10),h1(5,11);'line2_5',h1(6,1),h1(6,2),h1(6,3),h1(6,4),h1(6,5),h1(6,6),h1(6,7),h1(6,8),h1(6,9),h1(6,10),h1(6,11);'line2_6',h1(7,1),h1(7,2),h1(7,3),h1(7,4),h1(7,5),h1(7,6),h1(7,7),h1(7,8),h1(7,9),h1(7,10),h1(7,11);'line3_5',h1(8,1),h1(8,2),h1(8,3),h1(8,4),h1(8,5),h1(8,6),h1(8,7),h1(8,8),h1(8,9),h1(8,10),h1(8,11);'line3_6',h1(9,1),h1(9,2),h1(9,3),h1(9,4),h1(9,5),h1(9,6),h1(9,7),h1(9,8),h1(9,9),h1(9,10),h1(9,11);'line4_5',h1(10,1),h1(10,2),h1(10,3),h1(10,4),h1(10,5),h1(10,6),h1(10,7),h1(10,8),h1(10,9),h1(10,10),h1(10,11);'line5_6',h1(11,1),h1(11,2),h1(11,3),h1(11,4),h1(11,5),h1(11,6),h1(11,7),h1(11,8),h1(11,9),h1(11,10),h1(11,11)};
xlswrite('Coefficientl.xlsx',h2)
winopen('Coefficientl.xlsx')
h3={'before','fault';'line1_2',line(1,3);'line1_4',line(2,3);'line1_5',line(3,3);'line2_3',line(4,3);'line2_4',line(5,3);'line2_5',line(6,3);'line2_6',line(7,3);'line3_5',line(8,3);'line3_6',line(9,3);'line4_5',line(10,3);'line5_6',line(11,3)};
xlswrite('Initial_Powerl.xlsx',h3)
winopen('Initial_Powerl.xlsx')
if fl==8
P1(:,3)=P1(:,3).*100;
h4={'after','fault';'line1_2',P1(1,3);'line1_4',P1(2,3);'line1_5',P1(3,3);'line2_3',P1(4,3);'line2_4',P1(5,3);'line2_5',P1(6,3);'line2_6',P1(7,3);'line3_6',P1(8,3);'line4_5',P1(9,3);'line5_6',P1(10,3)};
xlswrite('Powerl.xlsx',h4)
winopen('Powerl.xlsx')
else
disp(['result of fault in Line',num2str(fl)]);
disp('____________________________________');
disp('line outputs after fault:');
P1(:,3)=P1(:,3).*100;
disp(P1);
end
end