Exercise 21 Solution

clear
[s, R] = promptSandR;
brakDist = calcbd(s, R);
printbd(brakDist)
%% local functions
function [a, b] = promptSandR
a = input('Enter the speed of the car in meters per second: ');
b = input('Enter the braking efficiency: ');
end
function b = calcbd(spd, brkeff);
g = 9.81;
b = spd.^2./(2.*brkeff.*g);
end
function printbd(bd)
fprintf('The braking distance (in meters) is %.1f\n', bd);
end


For more details, please contact me here.