% Generate 100 nodes randomly distributed in a square of Length x Length units n = 100; % load the position data load position.mat Length = 1; % Or generate a new set of position data % position = Length*rand(n,2); % radius that determines the neighbors of nodes r = Length/5; % draw neighbors and compute the incidence matrix of neighboring nodes [Eg,idx] = neighbors(n,position,r); % form the graph Laplacian L = Eg*Eg'; % kappa is taken as the diagonal of L kappa = diag(L); % Start solving the leader selection problem kval = 1:1:40; % pre-allocate memory for data collection Jlow = zeros(size(kval)); Jup = zeros(size(kval)); LSgreed = zeros(n,length(kval)); for i = 1:length(kval) Nl = kval(i); flag = 1; % for noise-corrupted leader selection formulation [Jlow(i),Jup(i),LSgreed(:,i)] = leaders(L,Nl,kappa,flag); end