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)); [sv, p] = sort(V(:,2)); figure; plot(sv, '.-'); %matlab2tikz('../ex6_6_ev.tex'); figure; subplot(1,2,1) spy(A); subplot(1,2,2) spy(A(p,p)); %matlab2tikz('../ex6_6_spy.tex'); fprintf("Group 1: "); display(sort(p(1:16))'); fprintf("Group 2: "); display(sort(p(17:end))');