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

Write a MATLAB function called midOps.m with the following specifications: Funct

ID: 2080029 • Letter: W

Question

Write a MATLAB function called midOps.m with the following specifications: Function will look at the conditions of an input value to determine what it does. Input value 1: A value (could be number, vector, matrix) Input value 2: B value (could be number, vector, matrix) Input value 3: C value (could be positive, negative or zero) Output value 1: Numerical result of operation Use the value of C as follows: If C is positive call the function midAdd() If C is negative call the function midSub() If C is zero display an error message (include why) and return C Write function midAdd() to take in two values and add to produce a result Write function midSub() to take in two values and subtract to produce a result Write function midMsg() to take in one value (use input value from midOps.m) and print a result Include help comments and body comments in each function Write an example using the function midOps.m

Explanation / Answer

midOps.m

function y = midOps(A,B,C)
if C>0%checks if C>0 to perfrom addition
y = midAdd(A,B);
elseif C<0%checks if C<0 to perfrom subtraction
y = midSub(A,B);
else%remains with C=0
y=C;
end
disp(midMsg(C));%to display message
end

midAdd.m

function a = midAdd(A,B)
a = A+B;%performs addition
end

midSub.m

function a = midSub(A,B)
a = A-B;%performs subtraction
end

midMsg.m

function m = midMsg(C)
if C>0
m = 'addition performed';
elseif C<0
m = 'subtraction performed';   
else
m = 'please provide correct input';
end
end

Command window example:


>> midOps(1,2,0)
please provide correct input

ans =

0

>> midOps(1,2,5)
addition performed

ans =

3

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