www.pudn.com > MATLAB.rar > MATLAB.txt, change:2015-11-09,size:1161b

```% Vehicle Matrices
A = [0 1; 0 -5];
B = [0; 1];
% Control Gains
F = -[15 1];
% Sample Time
T = 0.1;
% Number of vehicles
N = 3;
% Calculation of the Directed
% Laplacian
D = (N-1)*eye(N);
Q = ones(N,N)-eye(N);
Lg = D-Q;
% Compute complete matrices for the system
A1 = kron(eye(N),A);
B1 = kron(Lg,(B*F));
% Convert system into discrete time
A = (eye(2*N)+0.5*A1*T)/(eye(2*N)-0.5*A1*T);
B = T*B1;
% Formation positions
h1 = [ [2 0]; [0 0] ];
h2 = [ [0 0]; [0 0] ];
h3 = [ [2 2]; [0 0] ];
h = [h1;h2;h3];
% Number of iterations to run through
n = N*500;
x = zeros(n,2);
% Initial Conditions
% x(1:2*N,:) = 3*randn(2*N,2);
x(1:2,:) = [ [0 0]; [5 0] ];
x(3:4,:) = [ [0 1]; [0 3] ];
x(5:6,:) = [ [0 2]; [2 2] ];
% Determine new points
for i=2*N+1:2*N:n;
x(i:i+2*N-1,:) = A*x(i-2*N:i-1,:)+B*(x(i-2*N:i-1,:)-h);
end
x1 = x(1:2*N:n,1);
y1 = x(1:2*N:n,2);
x2 = x(3:2*N:n,1);
y2 = x(3:2*N:n,2);
x3 = x(5:2*N:n,1);
y3 = x(5:2*N:n,2);
% Plot results
figure(1);
plot(x1,y1,x2,y2,x3,y3);
hold on
plot(x1(end),y1(end),'o',x2(end),y2(end),'o',x3(end),y3(end),'o');
plot(x1(1),y1(1),'x',x2(1),y2(1),'x',x3(1),y3(1),'x'); hold off```