W = rand(30); W = W+W';
I = cell(3,1);
I{1} = 1:10; I{2} = 11:20; I{3} = 21:30;
vol = -ones(3,1);
for i = 1 : 3
vol(i) = sum(sum(W(I{i},I{i})));
end
Ncut_value = 0;
for i = 1 : 3
for j = 1 : 3
if j ~= i
Ncut_value = Ncut_value + sum(sum(W(I{i},I{j})))/vol(i);
end
end
end
Ncut_value = Ncut_value/2;
H = zeros(3, 30);
for i = 1 : 3
H(i,I{i}) = 1/sqrt(vol(i));
end
L = diag(sum(W,2))-W;
trace_value = sum(diag(H*L*H'));
disp([Ncut_value, trace_value])