Write a Matlab function Mytransitive that receives as an input the adjacency matrix of a graph G and outputs the adjacen

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Write a Matlab function Mytransitive that receives as an input the adjacency matrix of a graph G and outputs the adjacen

Post by answerhappygod »

Write a Matlab function Mytransitive that
receives as an input the adjacency matrix of a graph G and outputs
the adjacency matrix of Gt. Your function should check whether the
input is a square binary matrix and then use the function
Mysumadjacency. Hint: you can use the predefined function min that
accepts two matrices of the same size as input and outputs their
minimum computed component by component.
function [result] = issqbinary(x)
[row, cols] = size(x);
if row ~= cols
[result] = false;
fprintf('error - matrix is not sq')
return
else
[result] = true;
for ii = 1:length(x)
if x(ii) ~= 0 && x(ii) ~= 1
[result] = false;
fprintf('error - matrix is not
binary')
return
else
[result] = true;
end
end
end
end
function [result] = mysumadjacency(x)
if issqbinary(x) == true
g = graph(x,'upper');
A = adjacency(g);
f = full(A);
result = conv2(f, ones(length(x)),
'same');
else
result = false;
end
end
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply