Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following functions. What would be the response to the command line

ID: 3867575 • Letter: C

Question

Consider the following functions. What would be the response to the command line t = fun(5, 2) + fun(3, 4)? function [t] = fun(x, y) if x == 0 t = y: else t = fun(x - 1, x + y): end end Consider the following functions. What would be the response to the call foo(5)? Note that there is both a returned value and side effects. function x = foo(n) if mod (n, 2) == 1 disp(n): end if n > = 2 x = n - 2 + 3 * bar(n - 1): else x = 3: end function x = bar(n) if mod(n, 3) = 1 disp(n) end if n > = 2 x = 2 * n + 2 - foo(n - 1) else x = -2: end

Explanation / Answer

Hi,

Call to foo(5) wil return below error-

parse error near line 10 of file /home/cg/root/demo.m nested functions not implemented in this context >>> function x=bar(n)

Corrections in code-

if mod(n,3)=1 -->    if mod(n,3)==1
disp(n) --> disp(n);

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote