Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB Help: The body mass index is calculated by: BMI = (mass / height^2) * 703

ID: 3723749 • Letter: M

Question

MATLAB Help:

The body mass index is calculated by: BMI = (mass / height^2) * 703, where mass is in pounds and height is in inches.

Write a script hat will prompt the user for the sample size (validate for positive integer), and will generate one vector of random integers as mass data (90-200 Ibs) and a second vector of random integers as the height data (60-80 in). It will then call the updated function to calculate BMI, and it will finally display result in a formatted way (using fprintf() with a loop).

Thank you for the help!

Explanation / Answer

Hi,

As per the problem statement, Please find the solution with commented code

Please find the code below:

BMICalImpl.m:


% Calculate the BMI as follows
% BMI = (mass/height^2)*703

% Take the input from user
size = input("Please input the sample size ");
if size < 0
disp("Please enter the sample sizse as positive number");
exit;
end


% Generate random mass data as follows in range of 90-200 pounds
mass = 90+rand(1,size)*(200-90);

% Generate random height data as follows in range of 60-80 inches
height = 70+rand(1,size)*(80-60);


calBMI(mass, height,size);

Function : CalBMI.m

Please find the sample output below:

>> BMICalImpl
Please input the sample size 10
Calculated BMI for mass 179 and height 70 as result => 25.341829
Calculated BMI for mass 115 and height 71 as result => 15.982012
Calculated BMI for mass 133 and height 75 as result => 16.701361
Calculated BMI for mass 144 and height 73 as result => 18.997052
Calculated BMI for mass 193 and height 80 as result => 20.834851
Calculated BMI for mass 192 and height 72 as result => 25.390843
Calculated BMI for mass 119 and height 78 as result => 13.615287
Calculated BMI for mass 153 and height 87 as result => 14.214213
Calculated BMI for mass 134 and height 82 as result => 14.032554
Calculated BMI for mass 109 and height 73 as result => 14.363395
>>

Thanks


% Calculate the BMI as follows
% BMI = (mass/height^2)*703

% Take the input from user
size = input("Please input the sample size ");
if size < 0
disp("Please enter the sample sizse as positive number");
exit;
end


% Generate random mass data as follows in range of 90-200 pounds
mass = 90+rand(1,size)*(200-90);

% Generate random height data as follows in range of 60-80 inches
height = 70+rand(1,size)*(80-60);


calBMI(mass, height,size);