Z-bus matrix using MATLAB
Z-bus matrix using MATLAB
BEEE306P
Digital Assignment - 3
Simulation of Z-bus matrix
Navya Kukreja
22BEE0093
Aim
To calculate the elements zij of the impedance-bus matrix from the given bus
network.
Theory
Addition of a new branch
When a new node is created the dimensions of the matrix changes to (m + 1) x
(m+1) while the old Zbus matrix does not change.
1
Addition of new link
Since no new node is created, the modified Zbus will have the same dimension as
the original Zbus but all the elements of the modified bus will be different from
the original nodes
Z11 Z12 Z13
Zbus,old = Z21 Z22 Z23
Z31 Z32 Z33
Temporary bus is then,
Z11 Z12 Z13 Z1l
Z21 Z22 Z23 Z2l
Zbus,temp =
Z31
Z32 Z33 Z3l
Zl1 Zl2 Zl3 Zll
If new node connecting to existing bus:
Zli = Zpi − Zqi
Zll = Zpl − Zql + Zpl, pl
If new node connecting to refernce bus:
Zli = −Zqi
Zll = −Zql + Zpl, pl
Finally,
[Zil ][Zjl ]
Zbus,modif ied = Zbus,old − Zll
2
Algorithm
1. Initialize the ZBus matrix as a 1 × 1 zero matrix and start an iterative loop for
user inputs until the user wishes to exit.
2. If adding a new branch, check if it connects to a reference or existing bus.
3. If adding a new link, check if it connects from a reference or between existing
buses. Update the matrix using impedance and reduction formulas to reflect the
link’s effect.
4. Validate user inputs for bus IDs, ensuring they fall within the matrix size.
Display error messages for invalid data and continue or break as needed.
5. Repeat the process until the user chooses to exit, displaying the updated ZBus
matrix after every modification.
MATLAB code
clc ;
clear all ;
close all ;
Z_Bus_Matrix = [0];
temp_1 = 1;
while temp_1 == 1
temp_2 = input (" New branch or new link ? (1/2) : ") ;
if temp_2 == 1
temp_3 = input (" Addition of new branch with reference bus or existing
bus ? (1/2) : ") ;
if temp_3 == 1
z_new = input (" Enter new branch impedance : ") ;
Z_Bus = Z_Bus_Matrix ;
[i , j ] = size ( Z_Bus ) ;
Z_Bus ( i +1 , 1: j ) = 0;
Z_Bus (1: i , j +1) = 0;
Z_Bus ( i +1 , j +1) = z_new ;
if Z_Bus (1 , 1) == 0
Z_Bus = Z_Bus (2 , 2) ;
3
end
disp (" Impedance Matrix is :") ;
Z_Bus_Matrix = Z_Bus ;
Z_Bus_Matrix
elseif temp_3 == 2
temp_3 = input (" Enter the existing bus ID : ") ;
z_new = input (" Enter the new branch impedance : ") ;
Z_Bus = Z_Bus_Matrix ;
[i , j ] = size ( Z_Bus ) ;
if temp_3 <= j
Z_Bus ( i +1 , 1: j ) = Z_Bus_Matrix ( temp_3 , 1: j ) ;
Z_Bus (1: i , j +1) = Z_Bus_Matrix (1: i , temp_3 ) ;
Z_Bus ( i +1 , j +1) = Z_Bus ( temp_3 , j +1) + z_new ;
disp (" Impedance Matrix is :") ;
Z_Bus_Matrix = Z_Bus ;
Z_Bus_Matrix
else
disp (" False Data ") ;
break ;
end
end
elseif temp_2 == 2
temp_3 = input (" New link from reference bus or existing bus ? (1/2) : ") ;
if temp_3 == 1
temp_4 = input (" Enter the existing bus ID for the link : ") ;
z_new = input (" Enter the new link impedance : ") ;
Z_Bus = Z_Bus_Matrix ;
[i , j ] = size ( Z_Bus ) ;
if temp_4 <= j
Z_Bus_Temp = Z_Bus ;
Z_Bus_Temp ( i +1 , 1: j ) = Z_Bus ( temp_4 , 1: j ) ;
Z_Bus_Temp (1: i , j +1) = Z_Bus (1: i , temp_4 ) ;
Z_Bus_Temp ( i +1 , j +1) = Z_Bus_Temp ( temp_4 , j +1) + z_new ;
Z_Bus_Mod = Z_Bus - ((1 / Z_Bus_Temp ( i +1 , j +1) ) * Z_Bus_Temp (1:
i , j +1) * Z_Bus_Temp ( i +1 , 1: j ) ) ;
disp (" Impedance Matrix is :") ;
Z_Bus_Matrix = Z_Bus_Mod ;
Z_Bus_Matrix
else
disp (" False Data ") ;
break ;
end
elseif temp_3 == 2
temp_4 = input (" Enter the bus ID for link starting : ") ;
temp_5 = input (" Enter the bus ID for link ending : ") ;
z_new = input (" Enter the new link impedance : ") ;
4
Z_Bus = Z_Bus_Matrix ;
[i , j ] = size ( Z_Bus ) ;
if temp_4 > size ( Z_Bus_Matrix , 1) || temp_5 > size ( Z_Bus_Matrix , 2)
disp ( ' Invalid bus ') ;
continue ;
end
if temp_4 <= i && temp_5 <= j
Z_Bus_Temp = Z_Bus ;
Z_Bus_Temp ( i +1 , 1: j ) = Z_Bus ( temp_4 , 1: j ) - Z_Bus_Temp ( temp_5 ,
1: j ) ;
Z_Bus_Temp (1: i , j +1) = Z_Bus (1: i , temp_4 ) - Z_Bus_Temp (1: i ,
temp_5 ) ;
Z_Bus_Temp ( i +1 , j +1) = Z_Bus_Temp ( temp_4 , j +1) - Z_Bus_Temp (
temp_5 , j +1) + z_new ;
Z_Bus_Mod = Z_Bus - ((1 / Z_Bus_Temp ( i +1 , j +1) ) * Z_Bus_Temp (1:
i , j +1) * Z_Bus_Temp ( i +1 , 1: j ) ) ;
disp (" The impedance matrix is as follows :") ;
Z_Bus_Matrix = Z_Bus_Mod ;
Z_Bus_Matrix
else
disp (" Invalid input ") ;
break ;
end
end
end
temp_1 = input (" Continue or exit ? (1/0) : ") ;
end
5
Results
Output from MATLAB live editor:
Enter 1 for addition of new branch
Enter 2 for addition of new link: 1
Enter 1 for addition of new branch with reference bus
Enter 2 for addition of new branch with existing bus: 1
Enter new branch impedance: 1j
Impedance Matrix is:
6
Enter the existing bus ID: 2
Enter the new branch impedance: 0.25j
Impedance Matrix is:
7
Impedance Matrix is:
0.0000 + 0.5556i 0.0000 + 0.4444i 0.0000 + 0.5000i
ZBus,M atrix = 0.0000 + 0.4444i 0.0000 + 0.5556i 0.0000 + 0.5000i
0.0000 + 0.5000i 0.0000 + 0.5000i 0.0000 + 0.6250i
Enter 1 to Continue
Enter 0 to Stop: 0
Summary
We have successfully calculated the impedance matrix for the given bus system
and output is consistent with theoretical calculations.