In the U.S. fuel efficiency of cars is specified in miles per gallon (mpg). In E
ID: 3715421 • Letter: I
Question
In the U.S. fuel efficiency of cars is specified in miles per gallon (mpg). In Europe it is often expressed in liters per 100 km. Write a MATLAB user- defined function that converts fuel efficiency from mpg to liters per 100 km. For the function name and arguments, use Lkm-mpgToLpkm (mpg). The input argument mpg is the efficiency in mi/gl, and the output argument Lkm is the efficiency in liters per 100 km (rounded to the nearest hundredth). Use the function in the Command Window to: (a) Determine the fuel eficiency in liters per 100 km of a car whose fuel effi- ciency is 21 mi/gal. (b) Determine the fuel efficiency in liters per 100 km of a car whose fuel effi- ciency is 36 mi/gal.Explanation / Answer
%matlab code
% start fucntion
function Lkm=mpgToLpkm(mpg)
% conversion factor for (mile/gallon) to (Liter/100km)
Lkm=round(235.14/(mpg)*100)/100; % conversion factor for (Liter/100km)to (mile/gallon)
% rounding to the nearest 100th
end
% end function
%part a
mpgToLpkm(21)
Lkm = 11.2000
% part b
mpgToLpkm(36)
Lkm = 6.5300
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.