Home » Space Flight/Orbital Mechanics » Two Body Problem Numerical Solution,Satellite – Earth, R & V after dT

# Two Body Problem Numerical Solution,Satellite – Earth, R & V after dT

The initial position and velocity of an earth orbiting satellite in earth centered inertial frame is known. In this example we will numerically solve fundamental equation of relative two-body motion to find the distance of the satellite from the center of the earth and its speed after 24 hours.

```clc;
clear all;
R0 = [6750 0 0];          %[km]
V0 = [0 10.5 0];          %[km/s]
mu = 398600;            % Earth’s gravitational parameter [km^3/s^2]
t = 0;                  % initial time
dt = 10;                % time step [s]
dT = 24*3600;           % Time interval [s]
% Using fourth-order Runge–Kutta method to solve fundamental equation
% of relative two-body motion
F_r = @(R) -mu/(norm(R)^3)*R;
Rd = V0; R  = R0;
i = 1;
while (t <= dT)
Rv(i,:) = R;
tv(i) =t;
k_1 = dt*F_r(R);
k_2 = dt*F_r(R+0.5*k_1);
k_3 = dt*F_r(R+0.5*k_2);
k_4 = dt*F_r(R+k_3);
Rd  = Rd + (1/6)*(k_1+2*k_2+2*k_3+k_4);
Vv(i,:) = Rd;
R   = R + Rd*dt;
t   = t+dt;
i = i+1;
end
rn = (Rv(:,1).^2+Rv(:,2).^2+Rv(:,3).^2).^0.5;   % Radius Vector
vn = (Vv(:,1).^2+Vv(:,2).^2+Vv(:,3).^2).^0.5;   % Speed Vector
fprintf('Distance from Earth center = %4.2f [km] \n',norm(R));
fprintf('Satellite speed= %4.4f [km/s] \n',norm(Rd));```
```Distance from Earth center = 77061.78 [km]
Satellite speed= 1.5791 [km/s]```

Plots

```figure(1);
hold on;grid on;
plot(tv/3600,rn);
ylabel('Altitude [km]');
xlabel('Time [hour]');
title('Distance variation of the satellite from the center of the Earth');
figure(2);
hold on;grid on;
plot(tv/3600,vn);
ylabel('Speed [km/s]');
xlabel('Time [hour]');
title('Satellite speed variation');  ```