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

(p) [5 points] Create a variable named h_median1 and assign to it the median (mi

ID: 3788531 • Letter: #

Question

(p) [5 points] Create a variable named h_median1 and assign to it the median (middle) value of the elements contained in row vector h. Utilize built-in function median().
(q) [8 points] Repeat step (p), but this time, create a variable named h_median2 and assign to it the median value by indexing the middle element of row vector h_sorted. Compute the index of the middle element using a combination of built-in functions length() and round().

I have these data so far
a = [1:2:30]
c = [linspace(-10,10,15)]
h = 20.*(sin(2*a+(pi/4))).^2.*cos(5*c-(pi/3))+6.*(nthroot(c./a,3))/(a-c)
lab_part = 'Lab#3:Part#2';
disp(lab_part)
A = [3 1.5 1 0.5 4; -2 1 4 -3.5 2; 6 -3 2 2.5 1; 1 4 -3 0.5 -2; 3 2 -1 1.5 -3]
b = [-11.75 19 -23 -1.5 -3.5]'
x = A
lab_part = 'Lab#3:Part#3';
disp(lab_part)
h_average1 = mean(h)
h_average2 = sum(h)/length(h)
h_sorted = sort(h,'descend')
h_median1 = median(h)

Explanation / Answer

a = [1:2:30]
c = [linspace(-10,10,15)]
h = 20.*(sin(2*a+(pi/4))).^2.*cos(5*c-(pi/3))+6.*(nthroot(c./a,3))/(a-c)
lab_part = 'Lab#3:Part#2';
disp(lab_part)
A = [3 1.5 1 0.5 4; -2 1 4 -3.5 2; 6 -3 2 2.5 1; 1 4 -3 0.5 -2; 3 2 -1 1.5 -3]
b = [-11.75 19 -23 -1.5 -3.5]'
x = A
lab_part = 'Lab#3:Part#3';
disp(lab_part)
h_average1 = mean(h)
h_average2 = sum(h)/length(h)
h_sorted = sort(h,'descend')
h_median1 = median(h)
h_median2 = h_sorted(round(length(h_sorted)/2))
if ~mod(length(h_sorted), 2)
mid = length(h_sorted)/2
h_median2 = (h_sorted(mid) + h_sorted(mid+1))/2
end