please read carefully. need matlab code The speed of a sound wave is affected by
ID: 2080153 • Letter: P
Question
please read carefully. need matlab code
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-50 degree C. So, our equation for the speed in terms of a temperature C is: speed 331 + 0.6 astir 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:Explanation / Answer
Matlab Code:
function y = soundtemp()
%Calculates and prints the speed of sound by given a temperature entered by
% the user
C = input('Enter a temp in the range 0 to 50:');
if C<0 || C>50
y = 'Error in temperature';
else
speed= 331+(0.6*C);
y = fprintf('For a temperature of %d, the speed is :',speed);
end
end
output:
>> soundtemp
Enter a temp in the range 0 to 50:-5.7
ans =
Error in temperature
>> soundtemp
Enter a temp in the range 0 to 50:10
For a temperature of 337, the speed is :
ans =
40
>> help soundtemp
Calculates and prints the speed of sound by given a temperature entered by
the user
>>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.