This repository has been archived on 2021-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
NC/mp2/Project.2.Maggioni.Claudio/ex6.m

59 lines
977 B
Matlab

clc;
clear;
fileID = fopen('karate.adj','r');
row = split(strtrim(fgetl(fileID)));
n = size(row,1);
frewind(fileID);
ii = [];
jj = [];
vv = [];
for i = 1:n
row = split(strtrim(fgetl(fileID)));
for j = 1:n
num = str2double(row(j));
if num ~= 0
ii(end+1) = i;
jj(end+1) = j;
vv(end+1) = num;
end
end
end
fclose(fileID);
A = sparse(ii,jj,vv,n,n);
names = string(1:n);
disp("Exercise 6.1:");
degcentrality(names,A);
disp("Exercise 6.2:");
pagerank(names,A);
disp("Exercise 6.4:");
x = randperm(n);
gs = 450;
%group1 = [1 2 3 4 5 6 7 8 11 12 13 14 17 18 20 22];
%group2 = [9 10 15 16 19 21 23:34];
deg = sum(A);
L = full(diag(deg) - A);
[V, D] = eig(L);
fprintf("lambda_2: %d\n", D(2,2));
plot(sort(V(:,2)), '.-');
[ignore, p] = sort(V(:,2));
figure;
subplot(1,2,1)
spy(A);
subplot(1,2,2)
spy(A(p,p));
fprintf("Group 1: ");
display(sort(p(1:16))');
fprintf("Group 2: ");
display(sort(p(17:end))');