93.1k views
1 vote
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.

1 Answer

2 votes

Answer and Explanation:

Using MATLAB code:

Function Lkm = Lkm-mpgToLpkm (mpg)

Lkm= mpg*1.60934/3.78541;

Lkm= Lkm^(-1);

Lkm= Lkm*100;

%the code above defines a function Lkm and takes argument/input to its parameter mpg(miles per gallon) and then returns/output Lkm which is the litres per kilometers conversion from miles per gallon input.

end

To call the function written above with argument 30 mpg, we write:

Lkm= Lkm-mpgToLpkm (30)

User Matt Chambers
by
4.9k points