function [ybus, bsh, g, b] = getGridParameters(cd)  % Returns ybus

linedata = cd.branch(:, 1:6); % Calling "linedata6.m" for Line Data...
linedata(:,6) = ones(size(linedata, 1),1);
fb = linedata(:,1);     % From bus number...
tb = linedata(:,2);     % To b us number...
r = linedata(:,3);      % Resistance, R...
x = linedata(:,4);      % Reactance, X...
b = linedata(:,5)./2;   % Ground Admittance, B/2...
a = linedata(:,6);      % Tap setting value.. %Assumed 1

y = 1./(r + 1j*x);

nbus = max(max(fb),max(tb));    % no. of buses...
nbranch = length(fb);           % no. of branches...¨

%% Formation of Y-Bus Matrix
ybus = zeros(nbus,nbus);        % Initialise YBus... 
 % Formation of the Off-Diagonal Elements...
 for k=1:nbranch
     ybus(fb(k),tb(k)) = ybus(fb(k),tb(k))-y(k)/a(k);
     ybus(tb(k),fb(k)) = ybus(fb(k),tb(k));
 end
 % Formation of Diagonal Elements....
 for m =1:nbus
     for n =1:nbranch
         if fb(n) == m
             ybus(m,m) = ybus(m,m) + y(n)/(a(n)^2) + 1j*b(n);
         elseif tb(n) == m
             ybus(m,m) = ybus(m,m) + y(n) + 1j*b(n);
         end
     end
 end
 ybus;
 
%% Formation of the b bus
 
 bsh = zeros(nbus,nbus);
 for k=1:nbranch %putting all the values in the matrix
     bsh(fb(k),tb(k)) = b(k);
     bsh(tb(k),fb(k)) = bsh(fb(k),tb(k));
 end
 
g = zeros(nbus,nbus);
b = zeros(nbus,nbus);
gvec = real(y);
bvec = imag(y);
 for k=1:nbranch %putting all the values in the matrix
     g(fb(k),tb(k)) = gvec(k);
     g(tb(k),fb(k)) = g(fb(k),tb(k));
     b(fb(k),tb(k)) = bvec(k);
     b(tb(k),fb(k)) = b(fb(k),tb(k));
 end
end
