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

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

ID: 3799075 • Letter: F

Question

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

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. Click Test to test your solution before submitting it. When you are satisfied with it click Submit. Solution 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

Explanation / Answer

Here is the code you asked me for:

function fg = gradeCalc(h, q, e)

%The function should call a sub-function that creates a vector for each

%matrix with the average value for each row.

ha = average(h);

qa = average(q);

ea = average(e);

  

%The returned vectors should then be passed to another sub-function

%that calculates their weighted value, and returns a matrix with all

%the weighted values.

weightedMatrix = weighted(ha, qa, ea);

  

%Finally the returned weighted matrix should be passed to the third

%sub-function that returns a vector with the final grade for each

%student.

fg = finalGrade(weightedMatrix);

end

function out = average(in)

[rows, cols] = size(in);

for i = 1 : rows

out(i) = 0.0;

for j = 1 : cols

out(i) = out(i) + in(i, j);

end

out(i) = out(i) / cols;

end

end

function out = weighted(ha, qa, ea)

%30% homework, 30% quizzes and 40% exams.

for i = 1 : length(ha)

out(i, 1) = ha(i) * 30.0 / 100.0;

out(i, 2) = qa(i) * 30.0 / 100.0;

out(i, 3) = ea(i) * 40.0 / 100.0;

end

end

function out = finalGrade(in)

[rows, cols] = size(in);

for i = 1 : rows

out(i) = in(i, 1) + in(i, 2) + in(i, 3);

end

  

end