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/lecture.m

27 lines
578 B
Mathematica
Raw Normal View History

2020-09-29 11:58:49 +00:00
clear;
n = 1000;
x = randperm(n);
gs = 450;
group1 = x(1:gs);
group2 = x(gs+1:end);
p_group1 = 0.5;
p_group2 = 0.4;
p_between = 0.1;
A(group1, group1) = rand(gs, gs) < p_group1;
A(group2, group2) = rand(n-gs, n-gs) < p_group2;
A(group1, group2) = rand(gs, n-gs) < p_between;
% no group2, group1 needed since we'll force the matrix to be symmetric
A = triu(A,1); % upper triangular part of A without diagonal
A = A + A'; % make it symmetric
deg = sum(A);
L = diag(deg) - A;
[V, D] = eig(L);
display(D(2,2));
plot(sort(V(:,2)), '.-');
[ignore, p] = sort(V(:,2));
spy(A(p,p));