20.07.2013 Views

Software matematic

Software matematic

Software matematic

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

6.5. Tratarea evenimentelor 149<br />

y<br />

1<br />

0.8<br />

0.6<br />

0.4<br />

0.2<br />

0<br />

Corp in cadere<br />

tfinal = 1.6575<br />

0 0.2 0.4 0.6 0.8<br />

t<br />

1 1.2 1.4 1.6<br />

Figura 6.10: Traiectoria unui corp în cădere<br />

Sursa MATLAB 6.3 Problema celor două corpuri<br />

function orbit(reltol)<br />

y0 = [1; 0; 0; 0.3];<br />

opts = odeset(’events’, @gstop,’RelTol’,reltol);<br />

[t,y,te,ye] = ode45(@twobody,[0,2*pi], y0, opts, y0);<br />

tfinal = te(end)<br />

yfinal = ye(end,1:2)<br />

plot(y(:,1),y(:,2),’-’,0,0,’ro’)<br />

axis([-0.1 1.05 -0.35 0.35])<br />

%---------function<br />

ydot = twobody(t,y,y0)<br />

r = sqrt(y(1)ˆ2 + y(2)ˆ2);<br />

ydot = [y(3); y(4); -y(1)/rˆ3; -y(2)/rˆ3];<br />

%-------function<br />

[val,isterm,dir] = gstop(t,y,y0)<br />

d = y(1:2)-y0(1:2);<br />

v = y(3:4);<br />

val = d’*v;<br />

isterm = 1;<br />

dir = 1;

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

Saved successfully!

Ooh no, something went wrong!