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

~~~~~~~~~~~~~~~~Please use MATLAB to answer the following question. Also, please

ID: 3864628 • Letter: #

Question

~~~~~~~~~~~~~~~~Please use MATLAB to answer the following question. Also, please provide correct coding input and output - thanks!~~~~~~~~~~~

92 89 68 88 80 78 96 78 100 69 98 58 87 77 89 45 78 45 77 96 43 88 87 44 98 23 56 89 100 95 78 52 78 78 97 87 45 96 85 45 67 87 98 82 78 56 85 96 80 78 98 98 98 80 72 78 48 88 87 76 87 52 55 85 72 76 48 78 82 79 67 78 89 89 76 78 92 98 87 75 89 95 45 85 74 90 87 87 89 71 90 58 65 85 89 98 96 68 87 95 3. Write a function call AAge that takes three inputs arguments a, b and c representing ages of students and one output argument that represents the average age of the three numbers. Your function should do the following: i. Check to make sure the function is called with the right input arguments. While this function is defined to take three input argument, you can run the function with two values. If you run the function with two inputs, then your code should be smart to know that the missing input (c in this case) is the same as the first input (a in this case). Use nargin to help you achieve this. That is to say, if you run your code as AAge(10,12), you will get ans 10.667, and >>AAge (10, 12, 10) should give you ans 10.667 ii. Your code should check for non zero and non negative numbers. iii. Your code should check to make sure the inputs are all scalars. iv. this code wants to remove the bias of ages and hence it checks to make sure that the difference between the oldest and the youngest student is not more than 5 years. The code will only calculate average ages if the numbers are all within range.

Explanation / Answer

function avg = AAge(a,b,c)

h = 0;
l = 0;
if(a>0 && b>0 && isscalar(a) && isscalar(b))
if(a>b)
h = a;
l = b;
else
h = b;
l = a;
end
if(nargin == 3)
if(c>0 && isscalar(c))
if(c>h)
h = c;
elseif c < l
l = c;
end
if(h-l <= 5)
avg = (a+b+c)/3
else
disp('Invalid input')
else
disp('Invalid input')
end
elseif (nargin == 2)
avg = (a+b+a)/3
end
else
disp('Invalid input')
end

AAge(10,12)