In: Computer Science
I need to write a MATLAB code for this question, but I couldn't figure how to do it.
7. Engineers often have to convert from one unit of measurement to another; this can be tricky sometimes. You need to think through the process carefully. For example, convert 5 acres to hectares, given that an acre is 4840 square yards, a yard is 36 inches, an inch is 2.54 cm, and a hectare is 10000 m2.
First developing a formula to convert acres to hectares using the conversions given in the question.
The conversions given are:
1 acre = 4840 square yards
1 yard = 36 inches
1 inch = 2.54 cm
1 hectare = 10000 m2.
1 square yard = 362 inches2
= (36 x 2.54)2 cm2
Therefore,
1 acre = 4840 x (36 x 2.54)2 cm2
= 0.4047 x 108 cm2
= 0.4047 x 108 x 10-4 m2 (1 cm2 = 10-4 m2)
= 0.4047 x 104 m2
= 0.4047 hectares
So,
1 acre = 0.4047 hectares
Code:
y = AcresToHectares(5);
function hectares = AcresToHectares(acres)
hectares = 0.4047 * acres;
fprintf('%d acres converted into hectares is: %.3f hectares',acres,hectares);
end
Code screenshot:
Output: