I have the function file written. I need help testing the function with writing
ID: 1548148 • Letter: I
Question
I have the function file written. I need help testing the function with writing a separate script m-file that prompts the user for each mass and the distance between the two bodies, calls the new function created to calculate the gravitational force, and displays the gravitational force (4 decimal places) to the user. The gravitational force (F) between two bodies of masses is given by the and m2 m1 equation. G *m1* m2 Where G is the gravitational constant 6.672E-11 (6.672 x 10n-11) N m 2/kgn2, m1 and m2 are the masses of the bodies in kilograms, and r is the distance between the two bodies in meters. For this problem, write a MATLAB function that accepts two masses and a distance between them and calculates and returns the gravitational force between them. Then, test your function by writing a separate script m-file that prompts the user for each mass and the distance between the two bodies, calls the new function you created to calculate the gravitational force, and displays the gravitational force (with 4 decimal places) to the user. Run your script file using MATLAB to find the gravitational force on an 800kg satellite in orbit 38,000km above the center of the Earth. The Earth has a mass of 5.98E24 (5.98 x 10 24)kg. Submit your function m-file, your script m-file, and a screenshot of your command window after you have successfully run your script file to determine the gravitational force on the satellite.Explanation / Answer
% 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.672*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: 800
Enter mass2: 5.98*10^24
Enter distance between both mass: 38000
Gravitational Force between both masses is ....
%}