Exp 3 Code

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

% Ybus Formation

clc;
% Ask for number of buses
nbus=input('Enter number of buses. ');
y=zeros(nbus,nbus);
Y=zeros(nbus,nbus);
% Ask for admittance values
x=1;
while x>0
fprintf('Please select one of the following. \n');
fprintf('0. Exit\n1. Enter line impedence or admittance\n2. Enter line charg
ing admittance\n');
x=input('Your choice. ');
if x==1
busi=input('Input index of bus1(should be smaller of two) ');
busj=input('Input index of bus2(should be larger of two) ');
fprintf('Choose between impedence or admittance \n1. Impedence\n2. Admit
tance\n');
z=input('Your choice ');
if z==1
value=input('Enter impedence ');
y(busi,busj)=(1/value);
else if z==2
value=input('Enter admittance ');
y(busi,busj)=value;
end
end
Y(busi,busi) = Y(busi,busi)+y(busi,busj);
Y(busj,busj) = Y(busj,busj)+y(busi,busj);
Y(busi,busj) = Y(busi,busj)-y(busi,busj);
Y(busj,busi) = Y(busi,busj);
end
if x==2
busi=input('Enter bus index ');
y(busi,nbus+1)= input('Enter charging admittance ');
Y(busi,busi) = Y(busi,busi)+y(busi,nbus+1);
end
if x==0
break;
end
end
display(Y);

You might also like