function xdot=def_track(t,x,N,m,Ai,Bi,Pi,Fi,epsilon,Lg,d)

xdot = zeros(N*m,1);

%%%An expanded system: x(1)~x(8) are errors, x(9)~x(10) are reference
%%%trajectory

x_veh=x(1:8);
F=kron(eye(N,N),Fi);
L=kron(Lg,eye(m,m));
u_coop=-F*L*x_veh;

for i=1:2:2*N-1,
    xi=[x(i);x(i+1)];
    u=-epsilon*Bi'*Pi*xi;
    u1(i)=u(1);
    u1(i+1)=u(2);
    u2(i)=u_coop(i);
    u2(i+1)=u_coop(i+1);
end

for i=1:2:2*N-1,
    xdot(i)=x(i+1)+u1(i)+u2(i);
    xdot(i+1)=u1(i+1)+u2(i+1);
    u(i)=u1(i)+u2(i);
    u(i+1)=u1(i+1)+u2(i+1);
end


