0% found this document useful (0 votes)
16 views4 pages

Code Print Till YBUS

The document contains MATLAB functions for power system analysis, including main functions to input the number of buses, retrieve bus and line data, and compute the YBus matrix. The BUSDATA function defines bus parameters based on the number of buses, while the LINEDATA function provides line parameters. The YBUS function calculates the admittance matrix using the line data and bus connections.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

Code Print Till YBUS

The document contains MATLAB functions for power system analysis, including main functions to input the number of buses, retrieve bus and line data, and compute the YBus matrix. The BUSDATA function defines bus parameters based on the number of buses, while the LINEDATA function provides line parameters. The YBUS function calculates the admittance matrix using the line data and bus connections.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

4/3/25 10:38 AM C:\Users\lenovo\AppD...\main_121EE0702.

m 1 of 1

function main_121EE0702()
nb= input('no of buses: \n');%number of buses
Ybus_matrix = YBUS(nb);% gets Ybus matrix from the YBUS program
disp(Ybus_matrix);% display YBus

end
4/3/25 10:39 AM C:\Users\lenovo\AppData\Loca...\BUSDATA.m 1 of 1

function bus = BUSDATA(nbus)


% Format: [Bus No, Type, Vsp, Theta, Pg, Qg, Pl, Ql, Qmin, Qmax]
% Type: 1 - Slack, 2 - PV, 3 - PQ
%cases based on no of buses
switch nbus

case 4
bus=[1 1 0.5 0.3099 0 0 1 0 0 0;
2 3 1.7 1.0535 0 0 1 0 0 0;
3 3 2.0 1.2394 0 0 1 0 0 0;
4 2 0.8 0.4958 318 0 1 0 -5 5;];
case 1
bus=[1 1 0 0 0 0 1.05 0;
2 3 0 0 2 1 1.0 0;];
end
end
4/3/25 10:39 AM C:\Users\lenovo\AppData\Loc...\LINEDATA.m 1 of 1

function line = LINEDATA(nbus)


%[FB, TB, R, X, 1/2 B (Shunt), T]
switch nbus
case 2
line = [1 2 0 0.1 0 1];
case 3
line= [1 2 0 0.1 0 1;
1 3 0 0.05 0 1;
2 3 0 0.1 0 1];
case 4
line=[1 2 0.01008 0.0504 0.05125 1;
1 3 0.00744 0.0372 0.03875 1;
2 4 0.00744 0.0372 0.03875 1;
3 4 0.01272 0.0636 0.06375 1];
case 6
line = [1 2 0.10 0.20 0.02*2 1;
1 4 0.05 0.20 0.02*2 1;
1 5 0.08 0.30 0.03*2 1;
2 3 0.05 0.25 0.03*2 1;
2 4 0.05 0.10 0.01*2 1;
3 5 0.10 0.30 0.02*2 1;
4 6 0.07 0.20 0.025*2 1;
5 6 0.10 0.25 0.03*2 1;
];
case 9
line = [1 4 0 0.0576 0 1;
4 5 0.017 0.092 0.1580 1;
5 6 0.039 0.17 0.3580 1;
3 6 0 0.0586 0 1;
6 7 0.01129 0.068 0.2090 1;
7 8 0.0085 0.0720 0.1490 1;
8 2 0 0.0625 0 1;
8 9 0.032 0.1610 0.3060 1;
9 4 0.01 0.0850 0.1760 1;
];
end
end
4/3/25 10:39 AM C:\Users\lenovo\AppData\Local\T...\YBUS.m 1 of 1

function Y = YBUS(nb)
line_data = LINEDATA(nb);

FB=line_data(:,1);% 1st column = from bus


TB=line_data(:,2);% 2nd column = to bus
R=line_data(:,3);% 3rd column = resistance of line
X=line_data(:,4);% 4th column = reactaive impedence
B=line_data(:,5);%5th column = capacitive impedence
a=line_data(:,6);
z=R+1i*X;% total impedence of line
y=1./z;
n_buses=max(max(FB),max(TB));%numner of buses with line connected between them
n_lines=length(FB);% number of lines determined using number of rows
Y=zeros(n_buses);% initializing the YBus matrix

for i=1:n_lines
Y(FB(i,1),TB(i,1))=-y(i)/a(i);% fills non diagonal elements
Y(TB(i,1),FB(i,1))=-y(i)/a(i);% fills non diagonal elements

end
for i = 1:n_buses% filling diagonal elements in the matrix (series+shunt)
for j = 1:n_lines
if FB(j,1) == i
Y(i,i) = Y(i,i) + y(j,1)/(a(j,1)*a(j,1)) + B(j,1);
elseif TB(j,1) == i
Y(i,i) = Y(i,i) + y(j,1) + B(j,1);
end
end
end
end

You might also like