177k views
3 votes
Determine the output of the following function calls for part (a) and (b) below: (Do it yourself, and then you can check with MATLAB. You will have to do it yourself, without the computer, on the exam)

a. >>out = test1 (3)
function res = test1(x, y)
res = sqrt(x. 2 + y. 2);
b. >> out test2(3)
function res = test2 ( x , y )
if nargin == 2
res = sqrt ( x . 2 + y . 2 ) ; else
res = x;
end

User Emulbreh
by
8.3k points

1 Answer

1 vote

Final answer:

The output of the function calls in part (a) and (b) are 3 and 3, respectively.

Step-by-step explanation:

In part (a), the function call test1(3) will return the square root of the sum of 3 squared plus 0 squared, which is 3.

In part (b), the function call test2(3) will return the value 3 because the nargin parameter is equal to 2, so the function calculates the square root of the sum of 3 squared plus 0 squared.

User Tllewellyn
by
7.7k points

No related questions found