Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A marathon is 42 kilometers. Runners like to calculate their average speed based

ID: 3831138 • Letter: A

Question

A marathon is 42 kilometers. Runners like to calculate their average speed based on the time they would like to finish the marathon. Write a function called marathon Speed 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 km/hour 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.

Explanation / Answer

function myAvgSpeed = marathonSpeed(x)
j = size(x);
tmp = 0;
for i=1:j(2)
tmp = x(i)/60;
myAvgSpeed(i) = 42/tmp;
end
end

%-----------------------------------------------------------------------

>> x = [42 84 105 21]

>> marathonSpeed(x)

ans =

60.0000 30.0000 24.0000 120.0000

Verify with different test cases as required. Test cases are not mentioned.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote