第一章等切面曲线和相似曲线 图18慢跑者在椭圆上跑 >>xmax=max(maκ (y(:;1)) > ymin min (min min(y(:;2)) > ymax max (max (Y), max ( > clf hold on; >>axis [xmin xmax ymin ymax]) >> axis('equal); >> title (The Child and the Toy. ' >> stickhandle=line('Color','yellow,'EraseMode',> 'LineStyle,-,"XData',[,'YData',D >>for k 1: length(t)-1 >>p1ot(Ix(k),X(k+1)],[Y(k),Y(k+1)], 'Color,'yellow,'EraseMode','none); >>plot([y(k,1),y(k+1,1)],[y(k,2),y(k+1,2)],-3,… green set (stickhandle,'XData',[X(k+1), y(k+1, 1)] YData’,[Y(k+1),y(k+1,2)]) >> end >〉 hold off
rori and hrebicek 图1.9慢跑的狗 对于联接棒的直线类型的图形对象,我们定义变量 stickhandle为它的一个句柄.在循环内,我 们画出小孩和玩具的轨迹新的部分,并移动棒的位置.用 drawnow命令可即时画出这些图形,因 此,我们能看到同时画出两个轨迹和棒 在慢跑者和狗的情况下,我们不必定义句柄我们所作的只是以适当的顺序,画出两个轨迹 的各部分 > yo=[60; 70]; %initial conditions, starting point of the dog > options= odeset ('RelTol, 1e-5,'Events,'on >>t, Y=ode23 ('dog',[o, 20], yo, options) J=[] >> for h= 1: length(t) jc (J(:,1 >> xmax max (max (Y (:, 1)), max (J(:, 1))); > ymin = min (min (Y (: 2)), min (J(:, 2)));
第一章等切面曲线和相似曲线 13 =max(max(Y(:,2)),max(J(:,2)) >> axis ([xmin xmax ymin ymax]) title (The Jogger and the Dog. ) > for h= 1: length(t)-1 >>plot(Yh,1),Y(h+1,1)],[Y(h,2),Y(h+1,2)], co1or’,'ye11o none >>plot([J(h,1),J(h+1,1)],[J(h,2),J(h+1,2)],2:’, co1or),' green’,' EraseMode’,'none’); drawnow: pause(1) >end > hold off: 1.6具有恒定速率的慢跑者 在本节中,我们仍考虑慢跑者的椭圆轨迹.如果椭圆仍如算法17中所描述,并考虑t为时间 变量,则慢跑者的速度不是恒定的.令s(t)是描述中心在(m1,m2)和主半轴为a和b的椭圆的参 X(s)=mi +acos(s), Y(s)=m2+bsin(s) 我们希望确定,s是时间t的单调递增函数,使得对于等间隔的时间l,在椭圆的边界上,点 X(s(t1),Y(s(t1)之间也是等距离.一个等价的条件是慢跑者的速度v(t)为常数: dx(s(t)+ dy(s(t const dt 现在,为了得到s(t),先通过解方程(19),计算Ds=ds/dt Xe : m1 +a*cos(s(t): Ye m2 + b*sin(s(t)) Ve2: diff(Xe, t)2 +diff(Ye, t)2=V-2; Ve2:=a2 sin(s(t))2(s(t))2+bcos(s(t))2(s(t))2=V Ds solve(Ve2, diff(s(t), t)); Va2 sin((t)2+b2-b2 sin(s(t)2 va2sin(s(t)2+62-b2 sin(s())2
W. Gander. s. Barton and. hrebicek 因为慢跑者逆时针运动,我们必须选取第一个方程.微分方程没有解析解,所以我们将用 MATLAB 数值地求解它.加上两个微分方程(18),我们得到一个三对微分方程的系统: X(t)=mi + acos((t)) Y(t)=m2+bsin(s(t)) (t)=c(X(t)-x(t) i(t)=c(Y(t)-y(t)) s(t)= Va2in(()2+62co(()2 X 用函数£kt(算法1.8)实现此系统,由算法1.9给出对应的主程序 算法1.8具有常速度慢跑者的函数fkt function [ydot, isterminal, direction] = fkt(t, y, flag A for the jogger-dog problem h where the jo gger runs with constant Z velocity on an ellipse obal a b m cw A= cos(y(3);B= sin(y(3) h=[X:Y] -y (1: 2): nh norm(h) zs = (w/nh)*h if nargin <3 I isempty(flag)% normal output ydot =[zs; c/sqrt((a*B)"2+( else switch(flag) case 'events% at norm(h)=o there is a singularity ydot= nh-(1e-3):% zero crossing at pos_dog=pos_jogger 1; this is a stopping ever direction= o c don't care if decrease or increase otherwise error(['Unknown fl end 为了与以前的计算比较,我们选取方程(19)中的常数为第14节例子中慢跑者的平均速度 v(t)
第一章等切面曲线和相似曲线 >L:eva1f(4*int(sqrt(20^2*sin(f“2+15^2*cos(红)-2),f=0..Pi/2) > v: evalf(L/T) L:=110.5174608 V:=17.58940018 注意,如果执行算法19,则当t=8.22834时,狗赶上慢跑者,这比14节中的更早一点 算法1.9具有常速慢跑者的主程序 lobal a b b= 15: semi-axes >>m=[10;20]; >>c=17. 58940018;% constant velocity of jogger >>W=19; velocity of dog > yo =[60, 70, o]' ini. cond., starting point of the dog >>° ptions= odeset( Asto1’,1e-5, Events,on’) [t, Y]=ode23('fkt',[o 20], yo, options) >>clf: hold on; >>axi8([-1070-1070]); >>4 axis ( >>title(The Jogger Runs with Constant Velocity. ') >>p=length(t)-1 > for h=l: P >>p1ot([Y(h,1),Y(h+1,1)],[Y(h,2),Yh+1,2)],’-, yellow none )i >>B1=Y(h,3);s2=Y(h+1,3) X1=m(1)+a*cos(s1);Y1=m(2)+b*si(s1); >>X2=m(1)+a*cos(s2);Y2=m(2)+b*8in(82); ot([X1,X2],[Y1,Y2] Color,' green’,' EraseMode’,'none’) >> CrOSS(Y(P,1),Y(P,2),2) >>hold off 17利用移动的坐标系统 在本节中,我们将用 Cartesian坐标系,分别描述小孩和慢跑者的位置,用活动的极坐标分别 描述玩具和狗的位置,参见图1.10,活动的极坐标的原点,分别是小孩和慢跑者的位置,从而由距 离p(t)和极角叭(t),可确定玩具或狗的当前位置