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

· Pass the structure with five fields created in HStats.m to the function. · Com

ID: 3758618 • Letter: #

Question

·         Pass the structure with five fields created in HStats.m to the function.

·         Compute the following two items, BMR first then CMA, and put them as fields in a single structure:

BMR =

If Male, 66 + ( 6.23 x Weight ) + ( 12.7 x Height ) - ( 6.8 x Age )

If Female, 655 + ( 4.35 x Weight ) + ( 4.7 x Height ) - ( 4.7 x Age )

CMA =

For sedentary, BMR x 1.2

For Lightly Active, BMR x 1.375

For Moderately Active, BMR x 1.55

For Very Active, BMR x 1.725

For Extra Active, BMR x 1.9

·         Note that CMA does not depend on sex.

·         Return the computed structure.

Please perform the programming in MATLAB.

Explanation / Answer

function BMR(n) {

    // Women - 655 + (4.35 x weight in pounds) + (4.7 x height in inches) - (4.7 x age in years)
    function woman(weight, height, age) {
        return Math.floor(655 + (4.35 * weight) + (4.7 * height) - (4.7 * age));     }

    // Men - 66 + (6.23 x weight in pounds) + (12.7 x height in inches) - (6.8 x age in years )
    function man(weight, height, age) {
        return Math.floor(66 + (6.23 * weight) + (12.7 * height) - (6.8 * age));     }

    return n.isMale ? man(n.weight, n.height, n.age) :
        woman(n.weight, n.height, n.age);
}

function (app)
{
    app.factory('BMRService',
        function ()
        {
        return BMR;
    });
}