You are on page 1of 3

Lab Assignment 2

⦁ bus admittance matrix without incorporating the transformer tap ratio


clear
clc
w=readmatrix('labassignment2_22867.xlsx','sheet','data','range','A3:F22'); %taking the line parameters from the data in lab assignment file%
ans_notap= readmatrix('labassignment2_22867.xlsx','sheet','ybus without taps','range','A1:N14'); %taking the ans of ybus without taps to match after calcuation%
v=readmatrix('labassignment2_22867.xlsx','sheet','data','range','A26:F39'); %bus admittance parameters for shunt calculation %
eb=w(:,1); %column matrix indicating line begins from which bus%
sb=w(:,2); %column matrix indicating line ends at which bus%
r=w(:,3); %taking the resistance of each line%
x=w(:,4); %taking the reactance of each line%
b=w(:,5); %line charging admittance of each line%
ak=w(:,6); %tapping ratio %
shuntG=v(:,5); % conductance of shunt element connected at the y bus%
shuntB=v(:,6); %susceptance of shunt element connected at the y bus%
z=r+x*i; %impedance of each line%
len=length(z); %calculating the number of lines in the network%
y=1./z; %calculating admittance using elementwise operator on impedance matrix%
l=max(max(eb(:,1)),max(sb(:,1))); %no of buses in the y bus%
Y(l,l)=0; %initialising y bus as zero matrix of size nxn%
for k=1:len; %assigning k so that loop is executed 'len' no of times%
p=eb(k); %p indicates line starts from which bus%
q=sb(k); %q ndicates line ends at which bus%
Y(p,p)=Y(p,p)+y(k)+b(k)*i/2; %calculating the diagonal elements%
Y(q,q)=Y(q,q)+y(k)+b(k)*i/2; %by taking elements from sb and eb so that each line admiittance gets
added%
Y(p,q)=Y(p,q)-y(k); %off diagonal elements are calculated and as the Y matrix is symmetric so%
Y(q,p)=Y(p,q); %Y=Y'%
end
for j=1:length(shuntG) %shunt elements can be added at every bus so%
G=shuntG(j); %no of shunt elements =no of buses%
B=shuntB(j); %shunt elements only modifies the diagonal elements%
Y(j,j)=Y(j,j)+G+B*i;
end
for m=1:l %to check the answer from the table given%
for n=1:l %data is compared upto seven places from the decimal%
Y(m,n)=round(Y(m,n),7); %appropiate 'aa' matrix is calculated which compare %
ans_notap(m,n)=round(ans_notap(m,n),7); %the answers calculated elementwise%
if Y(m,n)==ans_notap(m,n)
aa(m,n)=1;
else
aa(m,n)=0;
end
end
end
aa
if Y==ans_notap
"ans is right"
Y
else
"ans is wrong"
end

1
⦁ bus admittance matrix with the transformer tap ratio
clear
clc
w=readmatrix('labassignment2_22867.xlsx','sheet','data','range','A3:F22'); %taking the line parameters from the data in lab assignment file%
ans_withtap= readmatrix('labassignment2_22867.xlsx','sheet','ybus with taps','range','A1:N14'); %taking the ans of ybus with taps to match after calcuation%
v=readmatrix('labassignment2_22867.xlsx','sheet','data','range','A26:F39'); %bus admittance parameters for shunt calculation %
eb=w(:,1); %column matrix indicating line begins from which bus%
sb=w(:,2); %column matrix indicating line ends at which bus%
r=w(:,3); %taking the resistance of each line%
x=w(:,4); %taking the reactance of each line%
b=w(:,5); %line charging admittance of each line%
ak=w(:,6); %tapping ratio %
shuntG=v(:,5); % conductance of shunt element connected at the y bus%
shuntB=v(:,6); %susceptance of shunt element connected at the y bus%
z=r+x*i; %impedance of each line%
len=length(z); %calculating the number of lines in the network%
y=1./z; %calculating admittance using elementwise operator on impedance matrix%
l=max(max(eb(:,1)),max(sb(:,1))); %no of buses in the y bus%
Y(l,l)=0; %initialising y bus as zero matrix of size nxn%
for k=1:len; %assigning k so that loop is executed 'len' no of times%
p=eb(k); %p indicates line starts from which bus%
q=sb(k); %q ndicates line ends at which bus%
a=ak(k); %transformer ratio of transformer connected between p and q%
d=max(p,q); %calculating the diagonal elements with transformer tappings%
e=min(p,q); %by taking elements from sb and eb so that each line admiittance gets added%
Y(d,d)=Y(d,d)+y(k)+b(k)*i/2;
Y(e,e)=Y(e,e)+y(k)/(a^2)+b(k)*i/2;
Y(d,e)=Y(d,e)-y(k)/a; %off diagonal elements are calculated and as the Y matrix is symmetric so%
Y(e,d)=Y(d,e); %Y=Y'%
end
for j=1:length(shuntG) %shunt elements can be added at every bus so%
G=shuntG(j); %no of shunt elements =no of buses%
B=shuntB(j); %shunt elements only modifies the diagonal elements%
Y(j,j)=Y(j,j)+G+B*i;
end
for m=1:l %to check the answer from the table given%
for n=1:l %data is compared upto seven places from the decimal%
Y(m,n)=round(Y(m,n),7); %appropiate 'aa' matrix is calculated which compare %
ans_withtap(m,n)=round(ans_withtap(m,n),7); %the answers calculated elementwise%
if Y(m,n)==ans_withtap(m,n)
aa(m,n)=1;
else
aa(m,n)=0;
end
end
end
aa
if Y==ans_withtap
"ans is right"
Y
else
"ans is wrong"
end

2
3

You might also like