0

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

ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
avostus
  • 1
  • 1
  • 1
    This is too much code. Isolate your problem: what is wrong? Is it throwing an error? Is it giving the wrong output? What is the expected output for a given input? – buzjwa Jan 26 '17 at 08:07
  • it doesnt give any error or output, my guess is that it is not able to get out of the "while loop" – avostus Jan 26 '17 at 10:34
  • It indeed looks like you have an infinite loop. Try to understand why, and if you fail, edit your question to include _only this issue_. – buzjwa Jan 26 '17 at 10:39
  • okok so that is what i'm going to do ! thank you !! – avostus Jan 26 '17 at 12:14

0 Answers0