Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Execute MATLAB/Octave Online

% compute the force of gravity between two objects given their masses and the distance between them
% masses are assumed to already exist in the workspace
mass1=81 %weight of mass 1 in kg. I used JBH weight in kg to confirm the lbs output at the end to be JBH weight in pounds
mass2=5.98*10^24; %weight of mass 2 in kg. I used earth's mass
distance= 6.371*10^6; %distance between centers of masses in meters. I used the radius of the earth to get from the center of earth to the center of my mass (which sits on the perimeter of the earth)
LBS_TO_NEWTONS_RATIO=4.4537;
gravitationalForceNewtons=(6.674*10^-11)*((mass1*mass2)/distance^2) % calculation taking the universal gravitation force formula and multiplying the masses which gets divided by the distance squared
gravitationalForceLbs=gravitationalForceNewtons/LBS_TO_NEWTONS_RATIO %using the constant assumption that 1 pound on Earth is the same as 4.4537 Newtons of force on Earth. This should end up at 178ish lbs

%attempt to code the exoweight.m script
%take weight in Earth pounds to print output of weight on 3 other celestial bodies (Venus, Mars, Jupiter) to be confirmed against website https://www.onlineconversion.com/weight_on_other_planets.htm
%Mars mass 6.39*10^23 kg radius 3390 km
%Venus mass 4.867*10^24 kg radius 6052 km
%Jupiter mass 1.898*10^27 kg radius 69911 km
MASS_MARS=6.39*10^23;
MASS_VENUS=4.867*10^24;
MASS_JUPITER=1.898*10^27;
RADIUS_MARS=3.390*10^6;
RADIUS_VENUS=6.052*10^6;
RADIUS_JUPITER=6.9911*10^7;
LB_TO_KG=0.454;
KG_TO_NEWTON=9.81;
%userWeight=input('what is your weight') %need to delete the percent symbol at the leading edge of this line whenever you've figured out how to get the user input
%mass1=userWeight; %need to delete the percent symbol at the leading edge of this line whenever you've figured out how to get the user input
% I cannot figure out how to call the code from the compute_gravitational_force.m to use it here for these three calculations. What I have done below just calculates each individual situation which is NOT the RIGHT way, but works
mass2=MASS_MARS;
distance=RADIUS_MARS;
marsWeight=((6.674*10^-11)*((mass1*mass2)/distance^2))/KG_TO_NEWTON/LB_TO_KG
mass2=MASS_VENUS;
distance=RADIUS_VENUS;
venusWeight=((6.674*10^-11)*((mass1*mass2)/distance^2))/KG_TO_NEWTON/LB_TO_KG
mass2=MASS_JUPITER;
distance=RADIUS_JUPITER;
jupiterWeight=((6.674*10^-11)*((mass1*mass2)/distance^2))/KG_TO_NEWTON/LB_TO_KG
%you will need to add semicolons after the jupiterWeight, venusWeight, and marsWeight lines in order to suppress the outputs until you know how to format the output in sentences, "You would weigh 67.49 lbs on Mars." "You would weigh 161.29 lbs on Venus." "You would weigh 471.36 lbs on Jupiter."

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.