找回密码
 注册
Simdroid-非首页
查看: 100|回复: 0

用Matlab模拟四人追逐问题

[复制链接]
发表于 2010-9-21 10:21:17 | 显示全部楼层 |阅读模式 来自 河北廊坊
看到有人用mathematica模拟,我也写了一个Matlab的模拟程序:


  1. clear;clc;close all
  2. rectangle('Position',[1,1,1,1],...
  3.     'Curvature',[0,0],...
  4.     'LineWidth',2,'LineStyle','-')
  5. axis([0.9 2.1 0.9 2.1])
  6. daspect([1,1,1])
  7. x=[1 1 2 2];
  8. y=[1 2 2 1];
  9. n=10000;
  10. axis off
  11. hold on
  12. h=zeros(length(x),1);
  13. for i=1:4
  14.     h(i)=plot(x(i),y(i),'r.','markersize',10,'erasemode','none');
  15. end
  16. title('\copyright:qibbxxt')
  17. t=0.001;
  18. dirx=[0,t,0,-t];
  19. diry=[t,0,-t,0];
  20. for i=1:n
  21.     x=x+t*dirx*i/10;
  22.     y=y+t*diry*i/10;
  23.     dirx=diff([x,x(1)]);
  24.     diry=diff([y,y(1)]);
  25.     if dist([x(1),y(1)],[x(2);y(2)])<15*t
  26.         break
  27.     end
  28.     arrayfun(@set,h,repmat({'xdata'},4,1),num2cell(x'),repmat({'ydata'},4,1),num2cell(y'));
  29.     pause(0.01);
  30. end
复制代码

mathematica程序见:http://forum.simwe.com/thread-949737-1-1.html

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×

评分

1

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Simapps系列直播

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-10-6 19:17 , Processed in 0.041017 second(s), 13 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表