-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.m
More file actions
62 lines (53 loc) · 1.12 KB
/
main.m
File metadata and controls
62 lines (53 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
%%% set up command window
clear
clc
format short
%%% set up globals
TOTAL_NODES = 25; % total number of nodes in this network
CONNECTIONS = [ ... % edges in this network (bi-directional connection)
1, 2; ...
2, 3; ...
3, 4; ...
4, 5; ...
4, 6; ...
6, 7; ...
7, 8; ...
8, 9; ...
7, 10; ...
10, 11; ...
11, 12; ...
12, 13; ...
12, 14; ...
14, 15; ...
10, 16; ...
16, 18; ...
16, 17; ...
17, 18; ...
18, 19; ...
18, 20; ...
19, 20; ...
20, 21; ...
21, 22; ...
22, 23; ...
23, 24; ...
23, 25; ...
];
%%% create laplacian matrix
laplacian = zeros(TOTAL_NODES, TOTAL_NODES);
[numR, numC] = size(CONNECTIONS);
for r=1:numR
nodeA = CONNECTIONS(r,1);
nodeB = CONNECTIONS(r,2);
% Aij = Aji = -1 when i ~= j
laplacian(nodeA, nodeB) = -1;
laplacian(nodeB, nodeA) = -1;
% update diagonal
laplacian(nodeA, nodeA) = laplacian(nodeA, nodeA) + 1;
laplacian(nodeB, nodeB) = laplacian(nodeB, nodeB) + 1;
end
%%% calculate eigen-values/vectors
[p,d] = eig(laplacian);
%%% display
disp(laplacian)
disp(p)
disp(d)