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 GibbsPooleStockmeyer 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
initialmatrix
degree Store degrees of nodes
end
methods
function obj ReorderingSSMm
obj.initialmatrix m;
obj.degree summ; Precompute degrees
end
function R CuthillMckeeobj
n sizeobjinitialmatrix, ;
degrees obj.degree;
Q ;
R zeros n;
notVisited true n;
position ;
while anynotVisited
i findnotVisited;
Qend i;
notVisitedi false;
while ~isemptyQ
u Q;
Q;
position position ;
Rposition u;
adjnodes findobjinitialmatrixu :;
~ idx sortdegreesadjnodes;
adjnodes adjnodesidx;
for v adjnodes
if notVisitedv
Qend v;
notVisitedv false;
end
end
end
end
R R:position; Truncate R to the actual size
end
function R ReverseCuthillMckeeobj
cuthill obj.CuthillMckee;
R flipcuthill;
end
function visualizeMatrixobj reordered
Visualize using improved graphics and better colormap
subplot;
spyobjinitialmatrix;
titleOriginal Matrix';
axis square;
subplot;
spyreordered;
titleCustom RCM Reordered Matrix';
axis square;
Visualizing the builtin reordered matrix
subplot;
rmatlab symrcmobjinitialmatrix;
reorderedmatlab obj.initialmatrixrmatlab, rmatlab;
spyreorderedmatlab;
titleMATLAB symrcm Reordered Matrix';
axis square;
end
end
end
script:
n ;
density ;
matrix sprandn n density;
Print the original order before reordering
fprintfOriginal order before reordering:
;
disp:n;
Creating an instance of ReorderingSSM with the generated matrix
m ReorderingSSMmatrix;
Timing and applying the custom Reverse CuthillMckee algorithm
tic;
rcustom mReverseCuthillMckee;
customTime toc;
Print the order after custom RCM reordering
fprintfOrder after custom RCM reordering:
;
disprcustom;
Timing and applying MATLAB's builtin symrcm function
tic;
rmatlab symrcmmatrix;
matlabTime toc;
Print the order after MATLAB's symrcm reordering
fprintfOrder after MATLAB symrcm reordering:
;
disprmatlab;
Reordering the matrix according to the custom RCM
reorderedmatrixcustom matrixrcustom, rcustom;
Print execution times
fprintfTime taken by custom RCM method: f seconds
customTime;
fprintfTime taken by MATLAB builtin symrcm method: f seconds
matlabTime;
Visualize the matrices
mvisualizeMatrixreorderedmatrixcustom;
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
