Write a MATLAB function called midOps.m with the following specifications: Funct
ID: 2079956 • 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.mExplanation / Answer
MAIN FUNCTION:
function [y]=midOps(A,B,C)
if length(C)==1
if C>0
y=midAdd(A,B);
elseif C<0
y=midSub(A,B);
else
fprintf('Error ');
y=0; C=0;
end
end
end
midAdd Function:
function [y]=midAdd(A,B)
D=(size(A)==size(B));
if D(2)==1
y=A+B
else
y=0;
fprintf('Matrix sizes not equal. ');
end
end
midSub Function:
function [y]=midSub(A,B)
D=(size(A)==size(B));
if D(2)==1
y=A-B
else
y=0;
fprintf('Matrix sizes not equal. ');
end
end
midMsg Function:'
function []=midMsg(C)
fprintf('Error');
end
OUTPUT:
A=[ 2 3 4];
>> B=[1 2 3 ];
>> C=100;
>> midOps(A,B,C)
y =
3 5 7
ans =
3 5 7
>>
C=-1;
midOps(A,B,C)
y =
1 1 1
ans =
1 1 1
>>
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.