0% found this document useful (0 votes)
16 views2 pages

Shreyas 1NT22EE099 POWERSYSTEM

Uploaded by

nh27mv9nxh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

Shreyas 1NT22EE099 POWERSYSTEM

Uploaded by

nh27mv9nxh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

clear;

clc;
disp('Z-bus Matrix Formulation');
numBuses = input('Enter the total number of buses: ');
zbus = zeros(numBuses);
continueLoop = true;
while continueLoop
fprintf('Current Z-bus Matrix:\n');
disp(zbus);
fprintf('\nMenu:\n');
fprintf('1. Connect new bus to reference bus\n');
fprintf('2. Connect existing bus to new bus\n');
fprintf('3. Connect between existing buses\n');
fprintf('4. Connect existing bus to reference bus\n');
fprintf('5. Display Z-bus Matrix\n');
fprintf('6. Visualize Z-bus Matrix\n');
fprintf('7. Exit\n');
choice = input('Enter your choice: ');
switch choice
case 1
zb = input('Enter the impedance value: ');
newBus = input('Enter the new bus number: ');
if newBus > 0 && newBus <= numBuses && zb > 0
zbus(newBus, newBus) = zb;
else
disp('Error: Invalid bus number or impedance value.');
end
case 2
existingBus = input('Enter the existing bus number: ');
newBus = input('Enter the new bus number: ');
zb = input('Enter the impedance value: ');
if existingBus > 0 && newBus > 0 && existingBus <= numBuses && newBus
<= numBuses && zb > 0
zbus(newBus, newBus) = zbus(existingBus, existingBus) + zb;
for i = 1:numBuses
if i ~= newBus
zbus(i, newBus) = zbus(i, existingBus);
zbus(newBus, i) = zbus(existingBus, i);
end
end
else
disp('Error: Invalid input. Please check the bus numbers and
impedance value.');
end

case 3
bus1 = input('Enter the first bus number: ');
bus2 = input('Enter the second bus number: ');
zb = input('Enter the impedance value: ');
if bus1 > 0 && bus2 > 0 && bus1 <= numBuses && bus2 <= numBuses && zb >
0
deltaZ = zb + zbus(bus1, bus1) + zbus(bus2, bus2) - 2 * zbus(bus1,
bus2);
if deltaZ ~= 0
ztemp = (1 / deltaZ) * ((zbus(:, bus1) - zbus(:, bus2)) *
(zbus(bus1, :) - zbus(bus2, :)));
zbus = zbus - ztemp;
else
disp('Error: Division by zero encountered in deltaZ
calculation.');
end
else
disp('Error: Invalid bus numbers or impedance value.');
end

case 4
existingBus = input('Enter the existing bus number: ');
zb = input('Enter the impedance value: ');
if existingBus > 0 && existingBus <= numBuses && zb > 0
deltaZ = zbus(existingBus, existingBus) + zb;
if deltaZ ~= 0
ztemp = (1 / deltaZ) * (zbus(:, existingBus) *
zbus(existingBus, :));
zbus = zbus - ztemp;
else
disp('Error: Division by zero encountered in deltaZ
calculation.');
end
else
disp('Error: Invalid bus number or impedance value.');
end
case 5
fprintf('Z-bus Matrix:\n');
disp(zbus);

case 6
figure;
heatmap(zbus);
title('Z-bus Matrix Heatmap');
xlabel('Bus Number');
ylabel('Bus Number');
G = graph(zbus ~= 0);
plot(G, 'EdgeLabel', G.Edges.Weight, 'NodeLabel', 1:numBuses);
title('Bus Network Graph');
xlabel('Bus Number');
ylabel('Bus Number');
case 7
disp('Exiting program.');
continueLoop = false;
otherwise
disp('Error: Invalid choice. Please select a valid option.');
end
end

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy