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

Problem Description: This function receives three matrices h (homework), q (quiz

ID: 3799040 • Letter: P

Question

Problem Description:

This function receives three matrices h (homework), q (quizzes) and e (exams). All matrices have the same number of unknown rows, one per student. Each has an unknown and not necessarily equal number of columns. The function should call for a sub-function that creates a vector for each matrix with the average value of each row. The returned vectors should then be passed to another sub-function that calculates their weighted value (30% homework, 30% quizzes and 40% exams) and returns a matrix with all the weighted values. Finally, the returned weighted matrix should be passed to a third sub-function that returns a vector with the final grade for each student (the addition of each row).

Instructions: To solve this problem, modify the template bellow with your code. Leave the names of the function and variables unchanged. Also maintain the names of the sub-functions. Otherwise your code will not pass the test. (In MatLab)

function fg = gradeCalc(h, q, e) % Don't change this line
% place your code here
end

%---------------------------------
function out = average(in)
% place the code for the average sub-function here
end

%---------------------------------
function out = weighted(ha, qa, ea)
% place the code for the weighetd sub-funciton here
end

%---------------------------------
function out = finalGrade(in)
% place your code for the finalGrade sub-function here
end

Explanation / Answer

Matlab function gradeCalc.m

function fg = gradeCalc(h, q, e) % This function receives three matrices h (homework), q (quizzes) and e (exams)
ha = average(h); % creates a vector for each matrix with the average value of each row
qa = average(q); % creates a vector for each matrix with the average value of each row
ea = average(e); % creates a vector for each matrix with the average value of each row
out = weighted(ha, qa, ea); % calculates their weighted value
fg = finalGrade(out); % final grade for each student
end

%---------------------------------
function out = average(in)
    out = mean(in')'; % average value of each row
end

%---------------------------------
function out = weighted(ha, qa, ea)
    out = [0.3*ha 0.3*qa 0.4*ea]; % weighted value MATRIX
end

%---------------------------------
function out = finalGrade(in)
    out = sum(in')'; % addition of each row FOR FINAL GRADE
end

Testing the result for three students

>> N = 3 ; % 3 students in the calss
>> h = floor(100*rand(N,5)); % 5 HW marks
>> q = floor(100*rand(N,10)); % 10 quizzes
>> e = floor(100*rand(N,3)); % 3 exams
>> fg = gradeCalc(h, q, e);
>> h

h =

    13    30    46    84    34
     3    29    64    55    44
    93    33     2    85     5

>> q

q =

    17    89    53    28    76    17    52    20    46    74
    66    11    70    41    81    35    33    90    91    73
    33    98    99    46    10     5    17    67    10    56

>> e

e =

    18    13     7
    59    21    24
    29    89     5

>> fg

fg =

31.646666666666665
43.296666666666667
42.710000000000008

>>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote