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
Write a Matlab function Mytransitive that receives as an input the adjacency matrix of a graph G and outputs the adjacen
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am