Write a function to calculate the gravitational force F between two bodies given their masses (m1 and m2) and the distance r between them as given above.
Write a script Gravity to test your function by determining the gravitational force (force) of an 800kg satellite (m2) in orbit 38 000km (r – note that r should be in metres) above the Earth. The mass (m1) of the Earth is 5.98 × 1024kg.
GravityForce.m:
function F = GravityForce(m1, m2, r)
%GravityForce Calculate the gravitational force F between two bodies
% m1 the mass of the first body (kg)
% m2 the mass of the second body (kg)
% r the distance between bodies (m)
% return the force F in N
G = 6.67408e-11;
F = G*m1*m2/r^2;
end
Gravity.m:
m1 = 5.98e24; % the mass of the Earth (kg)
m2 = 800; % the mass of a satelite (kg)
h = 38000; % an orbit of a satelite (km)
R_E = 6371; % the Earth radius (km)
r = (h + R_E)*1000; % distance between the Erth and a satelite (m)
F = GravityForce(m1, m2, r);
disp(['The gravity force between the Earth and a satelite is ' num2str(F) ' N'])
Comments
Leave a comment