clc
clear
close all
t0=0;tf=250;
step_qw=0.01;
p1=20;
q0=[(rand(1)-0.5)*p1;(rand(1)-0.5)*p1;0.2;0.2;
(rand(1)-0.5)*p1;(rand(1)-0.5)*p1;0.1;0.1;
(rand(1)-0.5)*p1;(rand(1)-0.5)*p1;0.1;0.1;
(rand(1)-0.5)*p1;(rand(1)-0.5)*p1;0.1;0.1;
(rand(1)-0.5)*p1;(rand(1)-0.5)*p1;0.1;0.1];
%这一组是赋初值,里面有些给的是随机值,也可以改成定值
%save('q0.mat','q0');
load('q0.mat','q0');
[t,q]=ode45('Whole_Twodimension_total_state',t0:step_qw:tf,q0);
figure(1);
hold on
xlabel('x position','FontName','Times New Roman','FontSize',14);ylabel('y position','FontName','Times New Roman','FontSize',14);
plot(q(:,1),q(:,2),'g');
hold on
plot(q(:,5),q(:,6),'r');
hold on
plot(q(:,9),q(:,10),'b');
hold on
plot(q(:,13),q(:,14),'k');
hold on
plot(q(:,17),q(:,18),'c');
hold on
legend('leader ','follower 1','follower 2','follower 3','follower 4',4);
hold on
plot(q(1,1),q(1,2),'ro');
hold on
plot(q(1,5),q(1,6),'bo');
hold on
plot(q(1,9),q(1,10),'bo');
hold on
plot(q(1,13),q(1,14),'bo');
hold on
plot(q(1,17),q(1,18),'bo');
hold on
plot(q(end,1),q(end,2),'rp');
hold on
box on
figure(2)
hold on
xlabel('t/s','FontName','Times New Roman','FontSize',14);ylabel('$\bar{v}_i$','interpreter','latex','fontsize',14);
hold on
plot(t,q(:,3),'r:',t,q(:,4),'r');
hold on
plot(t,q(:,7),'b:',t,q(:,8),'b');
hold on;
plot(t,q(:,11),'k:',t,q(:,12),'k');
hold on;
plot(t,q(:,15),'m:',t,q(:,16),'m');
hold on
plot(t,q(:,19),'m:',t,q(:,20),'m');
box on
legend('leader ','follower 1','follower 2','follower 3','follower 4',4);
figure(3)
hold on
xlabel('t/s','FontName','Times New Roman','FontSize',14);ylabel('xi-x0','interpreter','latex','fontsize',14);
hold on
plot(t,q(:,5)-q(:,1),'r:',t,q(:,6)-q(:,2),'r');
hold on
plot(t,q(:,9)-q(:,1),'b:',t,q(:,10)-q(:,2),'b');
hold on;
plot(t,q(:,13)-q(:,1),'k:',t,q(:,14)-q(:,2),'k');
hold on;
plot(t,q(:,17)-q(:,1),'m:',t,q(:,18)-q(:,2),'m');
hold on
legend('leader ','follower 1','follower 2','follower 3','follower 4',4);
box on
figure(4)
hold on
xlabel('t/s','FontName','Times New Roman','FontSize',14);ylabel('vi-v0','interpreter','latex','fontsize',14);
hold on
plot(t,q(:,3)-q(:,7),'r:',t,q(:,4)-q(:,8),'r');
hold on
plot(t,q(:,3)-q(:,11),'b:',t,q(:,4)-q(:,12),'b');
hold on;
plot(t,q(:,3)-q(:,15),'k:',t,q(:,4)-q(:,16),'k');
hold on;
plot(t,q(:,3)-q(:,19),'m:',t,q(:,4)-q(:,20),'m');
hold on
box on
legend('leader ','follower 1','follower 2','follower 3','follower 4',4);
grid off
- 1
- 2
前往页