Gravitational Force Function The gravitational force F betwe
Gravitational Force Function The gravitational force F between two bodies of masses m1 and m2 is given by the equation F= Gm_1m_2/r^2 where G is the gravitational constant (6.674 times10^-11 Nm^2/kg^2), m_1 and m_2 are the masses of the bodies in kilograms, and r is the distance between the centers of mass of the two bodies. Write a function to calculate the gravitational force between two bodies given their masses and the distance between them. Test your function by determining the force on a 1200 kg satellite in orbit 49,000 km above the center of mass of the Earth (the mass of the Earth is 5.972 times 10^24 kg). You must include a proper comment header block and you must use good programming practices.
Solution
% matlab code determine gravitational force F between two bodies
function force = gravitationalForce(m1,m2,r,G)
force = G*m1*m2/(r*r);
end
G = 6.674*10^(-11);
m1 = double(input(\"Enter mass1: \"));
m2 = double(input(\"Enter mass2: \"));
r = double(input(\"Enter distance between both mass: \"));
force = gravitationalForce(m1,m2,r,G);
fprintf(\"Gravitational Force between both masses is %f\ \",force);
%{
output:
Enter mass1: 1200
Enter mass2: 5.972*10^24
Enter distance between both mass: 49000
Gravitational Force between both masses is 199202638.900458
%}
