octave:>> % create matrix dimensions (square): octave:>> N=11; octave:>> % create empty (zeros) matrix, W: octave:>> W = zeros(N,N); octave:>> % Load matrix with data (wights: adjacency graph): octave:>> W(1,2) = 0.5; octave:>> W(1,5) = 0.5; octave:>> W(2,3) = 0.6; octave:>> W(3, 4) = 0.6; octave:>> W(4,5) = 0.6; octave:>> W(4,6) = 0.1; octave:>> W(5, 7) = 0.2; octave:>> W(6,7) = 0.8; octave:>> W(7,8) = 0.4; octave:>> W(8,9) = 0.5; octave:>> W(9,10) = 0.7; octave:>> W(10,11) = 0.7; octave:>> W(11,6) = 0.8; octave:>> N N = 11 octave:>> W W = 0.00000 0.50000 0.00000 0.00000 0.50000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.60000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.60000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.60000 0.10000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.20000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.80000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.40000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.50000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.70000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.70000 0.00000 0.00000 0.00000 0.00000 0.00000 0.80000 0.00000 0.00000 0.00000 0.00000 0.00000 octave:>> % Since it's undirected, add on the transpose to assign the edges in the other direction: octave:>> W = W + W'; octave:>> W W = 0.00000 0.50000 0.00000 0.00000 0.50000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.50000 0.00000 0.60000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.60000 0.00000 0.60000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.60000 0.00000 0.60000 0.10000 0.00000 0.00000 0.00000 0.00000 0.00000 0.50000 0.00000 0.00000 0.60000 0.00000 0.00000 0.20000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.10000 0.00000 0.00000 0.80000 0.00000 0.00000 0.00000 0.80000 0.00000 0.00000 0.00000 0.00000 0.20000 0.80000 0.00000 0.40000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.40000 0.00000 0.50000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.50000 0.00000 0.70000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.70000 0.00000 0.70000 0.00000 0.00000 0.00000 0.00000 0.00000 0.80000 0.00000 0.00000 0.00000 0.70000 0.00000 octave:>> % Examine the structure of the weights matrix (plots a graph!): octave:>> spy(W) octave:>> % Form the degree matrix, D: octave:>> D = diag(sum(W,2)); octave:>> % Form the Laplacian: octave:>> L = D - W; octave:>> % Find the eigenvectors and eigenvalues: octave:>> [evec,eval] = eig(L) evec = -0.30151134 -0.34661371 0.08459611 0.03758323 -0.68958301 0.03688039 -0.12175836 -0.52142867 -0.05261684 0.11629839 0.02211695 -0.30151134 -0.38180187 0.19700777 -0.19845456 -0.10794782 -0.53668820 0.10742769 0.53520029 0.25110059 0.15614907 0.00457272 -0.30151134 -0.35803616 0.09200361 -0.16633194 0.52236395 -0.22240875 -0.00542439 -0.34154622 -0.38246472 -0.39806175 -0.03200982 -0.30151134 -0.28448587 -0.10578535 0.05757365 0.44803493 0.42018808 -0.10293453 -0.09686370 0.33449398 0.54520239 0.08514783 -0.30151134 -0.25358999 -0.13019283 0.22162025 -0.15496585 0.54511807 0.06230231 0.47640603 -0.13337942 -0.44855804 -0.08780960 -0.30151134 0.20878548 -0.50597284 0.01842837 -0.00618426 -0.19547326 0.06737765 -0.16013980 0.35668149 -0.13868454 -0.62790427 -0.30151134 0.17744126 -0.34649281 0.40725920 -0.00030358 -0.22358982 0.48953089 -0.00187667 -0.32597489 0.22033294 0.38372573 -0.30151134 0.29325890 0.38846953 0.57337731 0.08940319 -0.16908559 -0.52937731 0.08475099 -0.06100685 0.02950229 -0.12174506 -0.30151134 0.33698018 0.50631783 -0.08706232 0.01644851 0.17404056 0.45219767 -0.17987143 0.40947367 -0.25634441 0.17555455 -0.30151134 0.32804672 0.15282355 -0.47276146 -0.05468039 0.19891628 0.05706939 0.13733070 -0.49380783 0.36606184 -0.33480757 -0.30151134 0.28001505 -0.33277457 -0.39123174 -0.06258567 -0.02789775 -0.47641101 0.06803848 0.09750082 -0.19189817 0.53315855 eval = Diagonal Matrix 6.8942e-16 0 0 0 0 0 0 0 0 0 0 0 8.3429e-02 0 0 0 0 0 0 0 0 0 0 0 6.0509e-01 0 0 0 0 0 0 0 0 0 0 0 6.9181e-01 0 0 0 0 0 0 0 0 0 0 0 8.0937e-01 0 0 0 0 0 0 0 0 0 0 0 8.8571e-01 0 0 0 0 0 0 0 0 0 0 0 1.6970e+00 0 0 0 0 0 0 0 0 0 0 0 1.9700e+00 0 0 0 0 0 0 0 0 0 0 0 2.1187e+00 0 0 0 0 0 0 0 0 0 0 0 2.2571e+00 0 0 0 0 0 0 0 0 0 0 0 2.8817e+00 octave:>>