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

Complete the following problems in MATLAB environment. Copy your command and fin

ID: 3282845 • Letter: C

Question

Complete the following problems in MATLAB environment. Copy your command and final answer from the MATLAB command window and paste them in a word document. Submit a single word document file for the entire HW. John's Grades in 6 different courses are 45, 50, 90, 75, 58 and 82. Amy's grades in these courses are 95, 50, 85, 77, 69 and 58. Write a SINGLE script and run it to answer the following questions a) To find and display the average of John's and Amy's grades b) To find which person (John or Amy) got better grades. c) How many courses has Amy gotten better grades than John? d) How courses has John gotten grades greater than 55 e) To display Amy's grades which are less than or equal to 85 f) How many courses have both Amy and John gotten same grades? g) To display the grades in item d h) How many courses has Amy gotten grades exactly equal to 81? i) To display Amy's grades which are 81. j) To display Amy's grade which are not less than 50 nor greater than 77 k) To display Amy's grade which are not between 65 and 85

Explanation / Answer

Here is the required MATLAB Code (Explanation in Comments) -

%% Data

J = [45, 50, 90, 75, 58, 82]; % John's Grades

A = [95, 50, 85, 77, 69, 58]; % Amy's Grades

%% (a)

avg_J = mean(J); % Calculate Average of John's Grades

avg_A = mean(A); % Calculate Average of Amy's Grades

fprintf("Average of John's Grades: %f ", avg_J);

fprintf("Average of Amy's Grades: %f ", avg_A);

%% (b)

% John has better grades if avg of his score is higher than Amy's

if(avg_J > avg_A)

fprintf("John has better Grades ");

elseif(avg_A > avg_J)

fprintf("Amy has better Grades ");

else

fprintf("Both have similar Grades ");

end

%% (c)

A_gt_J = sum(A > J); % Get the number of courses in which Amy Scored More

   % than John

fprintf("Number of Courses in which Amy scored better than John: %d ", A_gt_J);

%% (d)

J_gt_55 = sum(J > 55); % Get the number of courses in which John Scored More

   % than 55

fprintf("Number of Courses in which John scored better than 55: %d ", J_gt_55);

%% (e)

fprintf("Amy's Grades which are <= 85 are ");

A_leq_85 = A(A <= 85); % Get Grades Less than equal to 85

disp(A_leq_85);

%% (f)

same_grade = sum(A == J);

fprintf("Number of Courses with same grades: %d ", same_grade);

%% (g)

J_gt_55_grades = J(J > 55); % Get John's Grades which are more than 55

fprintf("John's Grades which are more than 55 are ");

disp(J_gt_55_grades);

%% (h)

A_eq_81 = sum(A == 81); % Get Grades equal to 81

fprintf("Number of Courses in which Amy got score 81: %d ", A_eq_81);

%% (i)

fprintf("Amy's Grades which are equal to 81 are ");

A_eq_81_grades = A(A == 81); % Get Grades Equal to 81

disp(A_eq_81_grades);

%% (j)

fprintf("Amy's Grades which are >=50 and <=77 are ");

A_geq_50_leq_77 = A((A >= 50) & (A <= 77)); % Get Grades Equal to 81

disp(A_geq_50_leq_77);

%% (k)

fprintf("Amy's Grades which are not between 65 and 85 are ");

A_nbtw_65_85 = A(~((A >= 65) & (A <= 85))); % Get Grades Not Between 65 and 85

disp(A_nbtw_65_85);

-----

Here is the output I got -

Average of John's Grades: 66.666667
Average of Amy's Grades: 72.333333
Amy has better Grades
Number of Courses in which Amy scored better than John: 3
Number of Courses in which John scored better than 55: 4
Amy's Grades which are <= 85 are
50 85 77 69 58

Number of Courses with same grades: 1
John's Grades which are more than 55 are
90 75 58 82

Number of Courses in which Amy got score 81: 0
Amy's Grades which are equal to 81 are
Amy's Grades which are >=50 and <=77 are
50 77 69 58

Amy's Grades which are not between 65 and 85 are
95 50 58