In: Advanced Math
Note: 1 meter = 39.3701 inch, 1 foot = 12 inches, 1 pound = 0.453592 kilogram
Solve this please using MATLAP
Answer:) The code for this function is as follows:
CODE:
%%% Function definition
function [ height_m, weight_kg ] = converter( height_in, weight_lb
)
% This function takes the height in inches and weight in pounds
as
% inputs, and outputs the height in meters and weight in
kilograms
feet = floor(height_in); % get the number of whole
feet
inches = 100*(height_in - feet); % get the number of
inches
height_m = (feet * 12 + inches) / (39.3701); % convert
feet to inches,
% and then convert inches
% to m
weight_kg = 0.453592 * weight_lb; % use the conversion
from pounds to kg
disp("Weight in kg : ")
disp(weight_kg)
disp("Height in m : ")
disp(height_m)
return
end
The code looks as follows when typed out in MATLAB:
Suppose we give the input height = 5 ft 15 inches, weight = 180 lb (given as an input which looks like (5.15, 180) ), we get :
>>converter(5.15, 180)
Weight in kg :
81.646559999999994
Height in m :
1.904998971300556
OUTPUT:
Note: the final 'ans' is just the function returning the first variable's value, and is the same as the height_m variable's value.
Suppose the user's weight is 170 lb, and the user's height is 6 ft 10 inches. This would be :
>> converter(6.10, 170)
Weight in kg :
77.110640000000004
Height in m :
2.082798875288606