I could really use some suggestions here :
So, what I am supposed to do is simulate a containment scenario over a graph (meaning that every node of the network will, eventually, join the convex hull defined by the state of the leaders of the graph; in this case, leaders are stationary and graph's topology is fixed). the procedure is based on the following :
Xi(k+1) = Xi(k) if node i is a leader on the graph
Xi(k+1) = Xi(k) + ∑Aij*(Xj(k)-Xi(k)) if node i is a follower on the graph
[if interested, more info in "containment control with
multiple stationary or dynamic leaders under a directed interaction graph]
My idea for the code is to start with a random input and elaborate it until containment is reached. what i have done so far :
clear all
clc
%%adjacency matrix; 4 leaders; 10 followers
%%leaders are not connected to other nodes
a=round(rand(14,14));
a=round((a+a')/2);
a([1:4],[1:end])=0;
a([1:end],[1:4])=0;
a=max(eye(14),a);
%%random inputs for leaders and followers; convex hull;
sl=randi(10,[2,4]);
cv=convhull(sl');
sf=randi(10,[2,10]);
s=[sl sf];
%%i need to compare the state of each follower with the convex hull
ssf=sf(:);
for i = 1 : length(ssf)
b = ssf(i)==cv(1:end);
c(:,i) = b;
end
j=sum(c);
s0=zeros(size(s));
%%go on with the procedure until j isnt a ones(1,20)
while (sum(j) <= 20)
s0=s;
for i = 1 : 14
for j = 1 : 14
s0(:,i) = s0(:,i) + a(i,j)*(s(:,j) - s(:,i));
end
end
s0=s;
sl=s(1:2,1:4);
sf=s(1:2,5:end);
ssf=sf(:);
for i = 1 : length(ssf)
b = ssf(i)==cv(1:end);
c(:,i) = b;
end
j=sum(c);
end
There is something wrong with the code, but I'm not able to fix it