Write MATLAB code to find Y bus for any bus system

In summary, the conversation discusses the process of creating a Ybus matrix using the step-by-step method for an any bus system. The code implements the algorithm for forming the off diagonal and diagonal elements of the matrix, but the resulting Ybus matrix does not match the expected result. The expert advises the programmer to use the MATLAB debugger to step through the code and identify any mistakes. They also suggest understanding the algorithm and solving it manually to aid in debugging.
  • #1
Fatima Hasan
319
14
Homework Statement
Write MATLAB code to find Y bus for any bus system, calculate Z, I, Bus voltages, and power of the following system (attached below).
Relevant Equations
-
Here's my work:
Matlab:
clc;
clear all;
% Ybus by step by step method for an any bus system

%         |  From |  To   |   R     |   X    |   gsh    |     B  |   T|ysh
%         |  Bus  | Bus   |  pu     |  pu    |    pu    |     pu   | ph-sh
linedata =  [1       2        0        -5         0          0        0
             1       3        0        -3         0          0        0
             2       3        0        -4         0          0        0];
        
fbus=linedata(:,1);             % Reading from bus
tbus=linedata(:,2);             % Reading to bus
R = linedata(:,3);              % Resistance, R...
X = linedata(:,4);              % Reactance, X...
gsh=linedata(:,5);
B = 1i*linedata(:,6);         % Ground Admittance, TOTAL..
T=linedata(:,7);
Z= R + 1i*X;                    % Z matrix...
y = 1./Z

buses = max(max(fbus),max(tbus));      % No. of buses...
lines = length(fbus);               % No. of elements...

%        Eg    Xg  Zd
BusData=[1     1   inf
        0      0   inf
        0      0   inf]   
 
Eg=BusData(:,1);
Xg=1i*BusData(:,2);
Zd=1i*BusData(:,3);
Zd=-1./Zd;
Xg=-Xg;   
ybus= zeros(buses,buses);       % Initializing YBUS as a zero matrix

for i=1:lines                % Forming the off diagonal elements
 if fbus(i)>0 && tbus(i)>0
     ybus(fbus(i),tbus(i))=ybus(fbus(i),tbus(i))-y(i);
    ybus(tbus(i),fbus(i))=ybus(fbus(i),tbus(i));     %same as opposite element
 end
endfor i=1:buses                   % Forming the diagonal elements
    for j=1:lines
        if fbus(j)==i || tbus(j)==i      % || represents  OR
            ysh(i,i)=(gsh(j)+B(j))/2;   
            ybus(i,i)=ybus(i,i)+y(j);   
        end
    end
end
yn=ybus+ysh+Xg+Zd   %Y
I=[Eg/Xg]           %I
Z=inv(yn)           % Z
V=inv(yn)*I         %Bus voltages

However, I got a different result from the corrected one (attached below). Could someone figure out my mistake please ?
 

Attachments

  • Ans.JPG
    Ans.JPG
    16.1 KB · Views: 137
  • Question.JPG
    Question.JPG
    12.9 KB · Views: 135
Physics news on Phys.org
  • #2
Its unreasonable to tell us:

I wrote this program and it doesn't work can you find my mistake?

You should instead use the MATLAB debugger and step through your code to see if its doing what you expect at every step.

Sadly, programmers must understand the algorithms they implement and be able to solve it manually in order to be able to debug their programs.

Work through your code and tell what line or lines you think its wrong. You can even put in print statements to show intermediate results and use the computer to compute some numbers to help you.
 
  • Love
Likes Tom.G

FAQ: Write MATLAB code to find Y bus for any bus system

What is Y bus in a bus system?

Y bus is a matrix that represents the admittance of a power system network. It consists of the shunt and series admittances of all the buses in the system and is used to calculate the power flow and voltage profile of the network.

Why is it important to find Y bus for a bus system?

Y bus is essential for analyzing the performance and stability of a power system. It is used in load flow studies, fault analysis, and other power system studies to determine the voltage and power flow at each bus in the network.

How do you write MATLAB code to find Y bus?

To write MATLAB code for finding Y bus, you need to first gather the necessary data, such as bus admittances, line parameters, and transformer data. Then, using the appropriate equations, you can calculate the Y bus matrix and store it in a variable. Finally, you can use this variable in your MATLAB code to perform power system analysis.

Can Y bus be different for different bus systems?

Yes, Y bus can vary for different bus systems depending on the network topology and the components present in the system. It is important to accurately calculate the Y bus matrix for each specific system to ensure accurate power system analysis.

Are there any limitations to using MATLAB for finding Y bus?

One limitation of using MATLAB for finding Y bus is that it requires a good understanding of power system concepts and MATLAB programming. It may also be time-consuming for large and complex bus systems. Additionally, the accuracy of the results depends on the accuracy of the input data and the assumptions made in the calculations.

Back
Top