Question: Write a matlab code in class for Gibbs - Poole - Stockmeyer algorithm and then call the functions like this in script file and then

Write a matlab code in class for Gibbs-Poole-Stockmeyer algorithm and then call the functions like this in script file and then do step wise explaination of how does the GPS bandwidth reduction of sparse matrix work. then do flop count analysis where you explain what is the total flop count
THis is for reverse cuthill mckee algorithm
classdef ReorderingSSM
properties
initial_matrix
degree % Store degrees of nodes
end
methods
function obj = ReorderingSSM(m)
obj.initial_matrix = m;
obj.degree = sum(m,2); % Precompute degrees
end
function R = CuthillMckee(obj)
n = size(obj.initial_matrix, 1);
degrees = obj.degree;
Q =[];
R = zeros(1, n);
notVisited = true(1, n);
position =0;
while any(notVisited)
i = find(notVisited,1);
Q(end +1)= i;
notVisited(i)= false;
while ~isempty(Q)
u = Q(1);
Q(1)=[];
position = position +1;
R(position)= u;
adj_nodes = find(obj.initial_matrix(u, :));
[~, idx]= sort(degrees(adj_nodes));
adj_nodes = adj_nodes(idx);
for v = adj_nodes
if notVisited(v)
Q(end +1)= v;
notVisited(v)= false;
end
end
end
end
R = R(1:position); % Truncate R to the actual size
end
function R = ReverseCuthillMckee(obj)
cuthill = obj.CuthillMckee();
R = flip(cuthill);
end
function visualizeMatrix(obj, reordered)
% Visualize using improved graphics and better colormap
subplot(1,3,1);
spy(obj.initial_matrix);
title('Original Matrix');
axis square;
subplot(1,3,2);
spy(reordered);
title('Custom RCM Reordered Matrix');
axis square;
% Visualizing the built-in reordered matrix
subplot(1,3,3);
r_matlab = symrcm(obj.initial_matrix);
reordered_matlab = obj.initial_matrix(r_matlab, r_matlab);
spy(reordered_matlab);
title('MATLAB symrcm Reordered Matrix');
axis square;
end
end
end
script:
n =500;
density =0.001;
matrix = sprand(n, n, density);
% Print the original order before reordering
fprintf('Original order before reordering:
');
disp(1:n);
% Creating an instance of ReorderingSSM with the generated matrix
m = ReorderingSSM(matrix);
% Timing and applying the custom Reverse Cuthill-Mckee algorithm
tic;
r_custom = m.ReverseCuthillMckee();
customTime = toc;
% Print the order after custom RCM reordering
fprintf('Order after custom RCM reordering:
');
disp(r_custom);
% Timing and applying MATLAB's built-in symrcm function
tic;
r_matlab = symrcm(matrix);
matlabTime = toc;
% Print the order after MATLAB's symrcm reordering
fprintf('Order after MATLAB symrcm reordering:
');
disp(r_matlab);
% Reordering the matrix according to the custom RCM
reordered_matrix_custom = matrix(r_custom, r_custom);
% Print execution times
fprintf('Time taken by custom RCM method: %.4f seconds
', customTime);
fprintf('Time taken by MATLAB built-in symrcm method: %.4f seconds
', matlabTime);
% Visualize the matrices
m.visualizeMatrix(reordered_matrix_custom);
keep the template of the class same just change the agorithm

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!