Advertisement
RaheemE

Y_Bus_from_Impedance_diagram

Apr 2nd, 2020
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.57 KB | None | 0 0
  1. % This software will convert the impedance diagram to Y-Bus matrix
  2. % Enter the data and this will prepare the Y-Bus matrix for you
  3. % Down a sample of data should be entered in this fashion
  4. % Coded by: RAHEEM ELSAYED
  5.  
  6. %   From        To          R           X           Yc/2
  7. Z = [1          2           0.05        0.15        0.01;
  8.      1          3           0.1         0.3         0.02;
  9.      2          3           0.15        0.45        0.03;
  10.      2          4           0.1         0.3         0.02;
  11.      3          4           0.05        0.15        0.01];
  12.  
  13. % Get the Y-Bus matrix dimensions
  14. buses = max(max(Z(:,1)), max(Z(:,2))); % The max between From and To
  15.  
  16. % Create the Y-Bus matrix - Initialized to zeros
  17. Y = zeros(buses, buses);
  18.  
  19. % Some variables used while forming the diagonal element of the Y-Bus matrix
  20. bus = 1;
  21. impedance = 0;
  22. c = 1;
  23. elements = [];
  24. admittance = [];
  25.  
  26. % Forming the diagonal element
  27. for zrow = 1:max(size(Z))
  28.    
  29.     for irow = 1:max(size(Z))
  30.         if ((Z(irow, 1) == bus) ||  (Z(irow, 2) == bus))
  31.             for column = 3:5
  32.                 if (column == 3)
  33.                     impedance = Z(irow, 3);
  34.                 elseif (column == 4)
  35.                     impedance = impedance + j*Z(irow, 4);
  36.                 else
  37.                     admittance(c) = (1/impedance) + Z(irow, column)*j;
  38.                     c = c + 1;
  39.                 end
  40.             end
  41.         end
  42.     end
  43.    
  44.     elements(zrow) = sum(admittance);
  45.    
  46.     for k = 1:max(size(admittance))
  47.         admittance(k) = 0;
  48.     end
  49.    
  50.     c = 1;
  51.     bus = bus + 1;
  52.    
  53. end
  54.  
  55. % Filter the diagonal elements from any zeros
  56. diagonal = elements(elements~=0);
  57.  
  58. % Here we form the of-diagonal elements and fill the Y-Bus matrix
  59. for row = 1:buses
  60.     for column = 1:buses
  61.         if (row == column)
  62.             Y(row, column) = diagonal(row);
  63.         else
  64.             for irow = 1:max(size(Z))
  65.                 if (((Z(irow, 1) == row) ||  (Z(irow, 2) == row)) && ((Z(irow, 1) == column) ||  (Z(irow, 2) == column)))
  66.                     for xcolumn = 3:5
  67.                         if (xcolumn == 3)
  68.                             impedance = Z(irow, 3);
  69.                         elseif (xcolumn == 4)
  70.                             impedance = impedance + j*Z(irow, 4);
  71.                         end
  72.                     end
  73.                    
  74.                     Y(row, column) = -1*(1/impedance);
  75.                    
  76.                 end
  77.             end
  78.         end
  79.     end
  80. end
  81.  
  82. % Here we display the resulted Y-Bus matrix
  83. disp('Y-Bus Matrix is:');
  84. disp(Y);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement