20.07.2013 Views

Software matematic

Software matematic

Software matematic

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

152 Ecuat¸ii diferent¸iale în MATLAB<br />

r = sqrt(1+t)*[cos(t); sin(t)];<br />

r_p = (0.5/sqrt(1+t)) * [cos(t)-2*(1+t)*sin(t);...<br />

sin(t)+2*(1+t)*cos(t)];<br />

dist = max(norm(r-y),1e-6);<br />

if dist > 1e-4<br />

factor = k*norm(r_p)/dist;<br />

yprime = factor*(r-y);<br />

else<br />

error(’Model ODE prost definit’)<br />

end<br />

Dacă distant¸a dintre vulpe s¸i iepure devine prea mică se apelează error. Script-ul<br />

de mai jos apelează fox1 s¸i produce figura 6.12. Pozit¸iile init¸iale sunt marcate prin<br />

cercuri.<br />

tspan = [0,10]; y0=[3,0]; k=0.75;<br />

[tfox,yfox] = ode45(@fox1,tspan,y0,[],k);<br />

plot(yfox(:,1),yfox(:,2)), hold on<br />

plot(sqrt(1+tfox).*cos(tfox),sqrt(1+tfox).*...<br />

sin(tfox),’--’)<br />

plot([3,1],[0,0],’o’)<br />

axis equal, axis([-3.5,3.5,-2.5,3.1])<br />

legend(’Vulpe’,’Iepure’,0), hold off<br />

3<br />

2<br />

1<br />

0<br />

−1<br />

−2<br />

Vulpe<br />

Iepure<br />

−3 −2 −1 0 1 2 3<br />

Figura 6.12: Exemplu de urmărire<br />

Implementarea de mai sus este nesatisfăcătoare pentru k > 1, adică atunci când<br />

vulpea este mai rapidă decât iepurele. În acest caz, dacă iepurele este prins în inter-

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!