作业帮 > 英语 > 作业

求MATLAB CODE 提示:

来源:学生作业帮 编辑:神马作文网作业帮 分类:英语作业 时间:2024/09/21 14:39:12
求MATLAB CODE 提示:
Three Ants in Pursuit:Consider three ants sitting at the vertices of an equilateral triangle whose sides are each 1 km long.The ants begin walking at the same time at speed s km per hour along a path towards the ant on their right.We are interested in plotting the path along which each ant walks.In order to simulate the ants' movement,consider their path as a sequence of straight-line paths taken over small time steps of length Δt.At the start of each time step,the direction of each ant is calculated,and the ant is advanced a distance of sΔt along that path.Repeat.
求MATLAB CODE 提示:
clear;clc;close all;
x=[0 1 0.5];
y=[0 0 sqrt(3)/2];
d=1e-3;
figure
hold on
plot([x 0],[y 0],'black');
while (x(1)-x(3))^2+(y(1)-y(3))^2>d^2
m=[x(2:3) x(1)];n=[y(2:3) y(1)];
a=m-x;b=n-y;
x0=x+a*d;y0=y+b*d;
plot([x;x0],[y;y0]);
x=x0;y=y0;
end