12 pts Function Calls Given the following functions test1 an
(12 pts) Function Calls Given the following functions test1 and test2, function res = test1(x,y)
else
res = x;
end end
determine whether the function calls below are correct or not. If they are correct, indicate the value of the variable out. If they are in error, specify what is wrong with them. You must “desk-check” your answers and write them out below by hand. You should not use MATLAB for this problem, unless it is to check your hand-work after you’ve finished.
a. out = test1();
b. out = test1(6);
c. out = test1(3,4)
d. out = test2(12);
e. out = test2(6,8);
f. out=test2(8,10,12);
Solution
a. out = test1(); this function call is wrong becase the function definition contains two arguments, but this call contains zero parameters.
b. out = test1(6);this function call is wrong becase the function definition contains two arguments, but this call contains one argument
c. out = test1(3,4) this call is correct which returns value of sqrt(32+42)=sqrt(25)=5
d. out = test2(12); this call is wrong because it contains one argument but we need two arguments.
e. out = test2(6,8);this call is correct;
narginchk(1,2) satisfies, because the function call minargs=1 and maxargs=2
because nargin=2, as number of arguments is equal to two, it returns sqrt(62+82)=10
f. out=test2(8,10,12); this call is wrong because it contains three rguments but we need two arguments.
