
%%%%%%%%%%%%%%%%%%%%%%%%
%All of this goes in one text file.
%The lines already written need not be modified
function orbit
%Find the motion of a particle
p.c=0.1;  p.m =1; p.M = 1; p.G = 1; 
x_0= 1;  ydot0 = 1.3;
t0= 0; tend=10;

tspan = [t0 tend];

r0 = [ x_0 0]'; v0 = [0 ydot0]';
z0= [r0; v0];

[tarray zarray] = ode45(@myrhs,tspan,z0,[],p);

x=zarray(:,1); y = zarray(:,2);
plot(x,y)
axis('equal')

d = norm(zarray(end,1:2));
disp(['The distance is' num2str(d)]);
end



function  zdot = myrhs(t,z,p)
r= z(1:2); v= z(3:4);
F_g = -p.G*p.m*p.M*   r/(norm(r))^3;
F_d = -p.c * v* norm(v);

rdot =v;
vdot = (F_g + F_d)/p.m;

zdot = [rdot;vdot];
end
%%%%%%%%%%%%%%%%%%%%%%%%

