In Matlab:
Given the script:
x = 1;
x = fun(x-1);
y = x-1
and the function:
function y = fun(x)
x = x-1;
y = x-1;
end
What is the output
a) -2
b) -4
c) -3
d) -1
c) -3 Explanation: ------------- function y = fun(x) x = x-1; y = x-1; end x = 1; x = fun(x-1); // calls fun with 1-1 = 0 x = x-1; changes x to 0-1 = -1 y = x-1; so, y = -1-1 = -2 so, function returns -1 y = x-1, y = -2-1 = -3 so, value of y is -3. since there is no semi-colon after y=x-1, value of y is printed. so, -3 is printed
Get Answers For Free
Most questions answered within 1 hours.