Given the following functions test 1 and test 2 function res
Given the following functions test 1 and test 2, function res = test1(x, y) res = squareroot (x.^2 + y.^2); end function res = test2(x, y) margins(1, 2) if margin = = 2 res = squareroot (x.^2 + y.^2); 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. out = test 1 (); out = test 1 (6); out = test 1 (3, 4) out = test 2(12); out = test 2(6, 8); out = test 2 (8, 10, 12);
Solution
a) b) d) and f) are worng as they are not passing the corret number of parameters to the functions and becuase the expected fucntion won\'t be called.
c) test1(3,4)
Now the call will go to first function test1 with x= 3 and y =4.
res = sqrt(x^2+y^2)
res = sqrt(3^2+4^2)
res = sqrt(9+16)
res = sqrt(25)
res = 5.
The value of out is 5
e) out = test2(6,8)
This will call the second function with x=6 and y= 8
Here first we have narginchk function with minarg limit as 1 and maxarg limit as 2.
Here we have passed two arguments which is inside limit so function will execute further and passed parameters are two so if condition satisfies and
res = sqrt(x^2+y^2)
res = sqrt(6^2+8^2)
res = sqrt(36+64)
res = sqrt(100)
res = 10
So the value of out is 10
