Hal9000 has written a pretty sweet MATLAB function! This function is supposed to
ID: 3857627 • Letter: H
Question
Hal9000 has written a pretty sweet MATLAB function! This function is supposed to take the oxygen levels on Discovery 1 as its first input and the rotation speed of the centrifugal artificial gravity environment as its second input.The function is then supposed to calculate the difference between the oxygen levels onboard and earth oxygen levels at sea level, and the difference between artificial gravity and earth gravity acceleration. Based on these differences, the function returns 4 outputs. v1 and v2 are variables that represent the three possible conditions of oxygen and gravity on the ship, respectively. m1 and m2 are supposed to be warning messages to the crew about the oxygen and gravity levels, respectively.
m1 should say:
- “Oxygen conditions are nominal.” if atmospheric differences between earth and Discovery 1 are minimal
- “Warning, low oxygen!” if oxygen levels are too low for life
- “Warning, fire hazard!” if oxygen levels are too high.
m2 should say:
- “Gravity is within norms.” if gravity is close to earth’s
- “Warning, normal functions may be difficult!”
- “Warning, beware of floating objects!” if gravity is too low.
Unfortunately, as Hal9000 is only artificially intelligent, he forgot to put any white space, tabs, or comments in his function, did not name his variables in an informative way, and put “I’m sorry, I can’t do that” for every string in his function. Download Hal’s program and do the following:
a. Include white space and tabs in places to make the program readable.
b. Add comments to the function to describe what each part is doing. You don’t need to add comments to every line, but it should be clear what every line does through commenting and variable names.
c. Change variable names to augment comments and make the code even more readable.
HOME PLOTS APPS EDITOR PUBLISHH MEW e Search Documentation Find Files Run Section Compare Go To Comment New Open Save Breakpoints Run and Print Find Advance NAVIGAT RUN ÷ ÷ 6 _/> Users» Egypt Documents·MATLAB Current Folder Editor-/Users/Egypt/Downloads/hal9000.m Workspace Name Name mainodesystem.modesystem.m hal9000.m+ Value Function [v1,V2,n1,n2] hal9800(o2,v) 3-if o 7 5- n1 = 'Sorry, I cannot do that.. ; v1-2; else 6- n1 ·Sorry, I cannot do that.. ; v1 = 3; 7end if w 9.81/2 m2 = 'Sorry, I cannot do that.';v2 = 2;else m2 = 'Sorry, I cannot do that,';v2 3; end 9- 10- 11- 12 Command Window New to MATLAB? See resources for Cetting Started. Academic License Details llReady Ln l Col 1Explanation / Answer
%{
This function is supposed to take the oxygen levels on Discovery 1 as its first input and the rotation speed of the centrifugal artificial gravity environment as its second input.The function is then supposed to calculate the difference between the oxygen levels onboard and earth oxygen levels at sea level, and the difference between artificial gravity and earth gravity acceleration. Based on these differences, the function returns 4 outputs.
Based on these differences, the function returns 4 outputs. The first two outputs are the three possible conditions of oxygen and gravity on the ship, respectively. The next two outputs are supposed to be warning messages to the crew about the oxygen and gravity levels, respectively.
Oxygen warning messages:
“Oxygen conditions are nominal.” if atmospheric differences between earth and Discovery 1 are minimal
“Warning, low oxygen!” if oxygen levels are too low for life
“Warning, fire hazard!” if oxygen levels are too high.
Gravity warning messages:
- “Gravity is within norms.” if gravity is close to earth’s
- “Warning, normal functions may be difficult!”
- “Warning, beware of floating objects!” if gravity is too low.
%}
function [
DifferenceLevelInOxygenOnShipVsEarth,
DifferenceLevelInGravityAcclrOnShipVsEarth,
OxygenWarningMsg,
GravityWarningMsg] =
CalculateOxygenGravityDifferenceLevelonDiscovery1ShipVsEarth
( OxygenonDiscovery1,RotationSpeedOfCentArtifiGravityonDiscovery1)
% initialize
OxygenOnEarth = 21;
EarthGravity=9.81;
RotationRadius=8;
CentripetalAcceleration=(RotationSpeedOfCentArtifiGravityonDiscovery1^2)/RotationRadius;
% Calculate the difference in oxygen and gravity
DifferenceInOxygen=OxygenOnEarth-OxygenonDiscovery1;
DifferenceInGravity = EarthGravity - CentripetalAcceleration;
% determine the oxygen level difference
if DifferenceInOxygen < -29
OxygenWarningMsg= 'Oxygen conditions are nominal' ;
DifferenceLevelInOxygenOnShipVsEarth=1;
elseif DifferenceInOxygen >7
OxygenWarningMsg= 'Warning, low oxygen!';
DifferenceLevelInOxygenOnShipVsEarth=2;
else
OxygenWarningMsg= 'Warning, fire hazard!';
DifferenceLevelInOxygenOnShipVsEarth=3;
end
% determine the gravity level difference
if DifferenceInGravity<(-EarthGravity/2)
GravityWarningMsg = 'Gravity is within norms.';
DifferenceLevelInGravityAcclrOnShipVsEarth=1;
elseif DifferenceInGravity>(EarthGravity/2)
GravityWarningMsg= 'Warning, normal functions may be difficult!';
DifferenceLevelInGravityAcclrOnShipVsEarth=2;
else
GravityWarningMsg= 'Warning, beware of floating objects!';
DifferenceLevelInGravityAcclrOnShipVsEarth=3;
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.