The following table shows the approximate speed of sound in air, water and steel
ID: 3528299 • Letter: T
Question
The following table shows the approximate speed of sound in air, water and steel Write a function M-file that has two input arguments. The first is a number to select air (1) water (2) or steel (3). The second is the distance that the sound wave will travel in the selected medium. The output argument is the time that the sound wave has travelled. Be sure to include input error checking, using MATLAB built-in error, to ensure that only 1,2 or 3 is selected as the first input, and do not allow negative distances. For example: HW4_6(1,1200) ans =1.0909 HW4_6(5,1200) Error using HW4_6 (line 11) Please choose 1 (air), 2 (water) or 3 (steel)Explanation / Answer
function ans=HW4_6(choice,distance)
switch(choice)
case 1
speed=1100;
case 2
speed=4900;
case 3
speed=16400;
otherwise
error('Please choose 1 (air), 2 (water) or 3 (steel)');
end
ans=distance/speed;
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.