A. (5 points) A marathon is 42 kilometers. Runners like to calculate their avera
ID: 3819485 • Letter: A
Question
A. (5 points) A marathon is 42 kilometers. Runners like to calculate their average speed based on the time they would like finish the marathon. Write a function called marathonSpeed that will accept a vector of different runners' target completion times in whole number of minutes; the function returns a vector of the average speed in kmshour corresponding to each completion time. Call your function with a vector argument of at least three different completion times, and assign the returned valued to a variable call myAvgSpeed. If you were to add error checking, what error checking should you do on the argument? Create a test table and write matlab function to solve the problem. Design will be done in lecture or lab. Sample Data pected Result verilmed? (manually calculate) Test CaseExplanation / Answer
%matlab code
% error checking can be done in minutes vector ensuring that all the elements in minutes vector
% are positive as minutes cannot be less than zero
function myAvgSpeed = marathonSpeed(minutes)
% convert minutes to hours
hours = minutes/60;
distance = 42;
myAvgSpeed = [];
for i=1:length(hours)
myAvgSpeed(i) = distance/hours(i);
end
end
marathonSpeed([100,275,328,411,534,600,712,138,110])
%output: 25.2000 9.1636 7.6829 6.1314 4.7191 4.2000 3.5393 18.2609 22.9091
marathonSpeed([113,575,638,451,364,320,112,158,230])
%output: 22.3009 4.3826 3.9498 5.5876 6.9231 7.8750 22.5000 15.9494 10.9565
marathonSpeed([300,555,568,131,134,510,122,458,310])
%output: 8.4000 4.5405 4.4366 19.2366 18.8060 4.9412 20.6557 5.5022 8.1290
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.