The speed of a sound wave is affected by the temperature of the air. At 0 degree
ID: 3826115 • Letter: T
Question
The speed of a sound wave is affected by the temperature of the air. At 0 degree C. the speed of a sound wave is 331 m/sec. The speed increases by approximately 0.6 m/sec for every degree (in Celsius) above 0; this is a reasonably accurate approximation for 0-50degree C. So, our equation for the speed in terms of a temperature C is: speed =331 + 0.6 * C Write a script soundtemp that will prompt the user for a temperature in Celsius in the range from 0 to 50 inclusive, and will calculate and print the speed of sound at that temperature if the user enters a temperature in that range, or an error message if not. Here are some examples of using the script: >> soundtemp Enter a temp in the range 0 to 50: -5.7 Error in temperature >> soundtemp Enter a temp in the range 0 to 50: 10 For a temperature of 10.0, the speed is 337.0 >> help soundtemp Calculates and prints the speed of sound given a temperature entered by the userExplanation / Answer
%Calculates and prints the speed of sound given a
%temperature entered by the user
#save as soundtemp
#The above two lines will be printed for command <<help soundtemp >>
#prompt user to enter temp
temp=input('Enter a temp in the range 0 to 50 :');
#checking if tmep<0
if temp<0
fprintf('Error in temperature ')
else
#calculate speed
speed=331+0.6*temp;
#print speed to console
fprintf('For a temperature of %5.2f, the speed is %5.2f ',temp,speed)
end
------------------------------------------------------------------------------------------------------------
sample output:
>> soundtemp
Enter a temp in the range 0 to 50 :-5
Error in temperature
>> soundtemp
Enter a temp in the range 0 to 50 :10
For a temperature of 10.00, the speed is 337.00
>> help soundtemp
Calculates and prints the speed of sound given a
temperature entered by the user
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.