
% Program to compute the trajectory of a falling apple.

clear
G = 6.7000e-11;  % gravitational constant, m3/kg/s2
mEarth = 5.9e24;  % mass of earth, kg
rEarth=6.3e6;   % radius of earth, m

dt=1;   % subinterval length, s
N = 5;  % number of subintervals

t(1)=0;           % start time
r(1)=rEarth+100;  % initial position 100m above the surface of earth
v(1)=0;           % initial velocity

for i=1:N
    t(i+1)=t(i)+dt;
    r(i+1)=r(i)+v(i)*dt;             % Eq. (1)in paper
    v(i+1)=v(i)-G*mEarth/r(i)^2*dt;  % Eq. (2)
end 

plot(t,r-rEarth)  % plot apple's trajectory
grid
xlabel('t')
ylabel('r - rEarth')
title('The trajectory of Newton-s apple')