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

Write one complete Matlab Function script and one complete Test script, given th

ID: 2249382 • Letter: W

Question

Write one complete Matlab Function script and one complete Test script, given the following 1. bx5 a=2 DATA = [1 2 3 4 5] Test Script: Function Script: SUM = a + b + c MAX max(DATA) MIN min(DATA) Function Script (Two Output arguments& Three Input arguments): - Save the Function script as compute.m - Perform calculations and return variables depending on user's request Test your Function. Call the Function from a separate test.m script Display the required (desired) information. NOTE: All values must be received and returned via the Function's input/output arguments. NO EXCEPTION ! This time I mean it Case 1: If user enters the word 'SUM' from keyboard and requests only one value to be returned from the function: script compute. m will provide a default value of c 12, calculate SUM, and then return the value of variable SUM. Only script test.m will display it on the screen. Case 2: If user enters the word 'STATS' from keyboard and requests two values to be returned from the function script compute.m will calculate the min() and max() values and then return the values of variables MIN and MAX. Only script test.m will display them on the screen. Case 3: If user enters anything else from keyboard, function will return the message "Something Went Wrong". Only script test.m will display the message on the screen

Explanation / Answer

test.m script:

a = 2;b=5;
DATA = [1 2 3 4 5];
req = input('Please enter the requirement:','s');
if strcmp(req,'SUM')%checks if requirement is SUM
SUM = compute(a,b);%only one value to be returned and passes only a and b because c is default 12 which is already defined in compute.m
disp('SUM is:');
disp(SUM);
elseif strcmp(req,'STATS')%checks if requirement is STATS
[MIN MAX] = compute(DATA);
disp('Min and Max are');
disp([MIN MAX]);
else
disp('Something went wrong');
end

compute.m script:

Please enter the requirement:SUM
SUM is:
19

Please enter the requirement:STATS
Min and Max are
1 5

Please enter the requirement:Hello
Something went wrong
>>

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