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

Using MATLAB For this problem, do not run the code in MATLAB, instead try to fin

ID: 3823675 • Letter: U

Question

Using MATLAB

For this problem, do not run the code in MATLAB, instead try to find the answer based on your knowledge from MATLAB commands. Write the screen display for the following script and associated functions in the space provided. Credit only given for work shown. In you need more rows, add more rows to the bottom of the table. function myfunc() clc close all clear all x = 4 y = 3 z = [2 4 5 3 1]; for i = 1: 3: 8 if (i 3) disp ('done') else back 2 = fcn 2 (i, y, x, z) end end function [out 2] = f cn 1 (j, y, x, k) ou 2 = [0 0 0 0 0] for i = 1: 1: 5 out 2 (i) = fcn 2 (i, x, y, k); end end function [out 1] = fcn 2 (j, d, s, k) switch (k (j)) case {1, 2} out 1 = d + 4 case {3, 4} ou 1 = 2*s otherwise out 1 = d + s end end end

Explanation / Answer

function myfunc()

clc

close all

clear all

  

x = 4 %As there is no ; at the end, it will be printed to screen x = 4 (Line1)

y = 3 %As there is no ; at the end, it will be printed to screen y = 3 (Line2)

z = [2 4 5 3 1]; %z is initialized.

for i = 1 : 3 : 8 %This loop runs for values: 1, 4, 7.

if i <= 2 %For value 1, i is less than or equal to 2.

back1 = fcn1(i, x, y, z) %So, this method is called, with values 1, 4, 3, [2, 4, 5, 3, 1] and will print [7 8 7 8 7] (Line 9)

elseif i > 3 %For both values 4, and 7 as they are > 3

disp('done') %done will be displayed (Line 10, 11)

else

back2 = fcn2(i, y, x, z)

end

end

  

function [out2] = fcn1(j, y, x, k) %Here j = 1, y = 4, x = 3, k = [2, 4, 5, 3, 1]

out2 = [0 0 0 0 0] %As there is no ; at the end, it will be printed to screen out2 = [0 0 0 0 0] (Line3)

for i = 1 : 1 : 5 %This loop runs for values 1, 2, 3, 4, 5

out2(i) = fcn2(i, x, y, k); %out2(1) = fcn2(1, 3, 4, [2, 4, 5, 3, 1])

%out2(2) = fcn2(2, 3, 4, [2, 4, 5, 3, 1])

%out2(3) = fcn2(3, 3, 4, [2, 4, 5, 3, 1])

%out2(4) = fcn2(4, 3, 4, [2, 4, 5, 3, 1])

%out2(5) = fcn2(5, 3, 4, [2, 4, 5, 3, 1])

end %So, out2 will be [7 8 7 8 7] will be returned.

end

function [out1] = fcn2(j, d, s, k) %Here j = 1, d = 3, s = 4, k = [2, 4, 5, 3, 1]

%Here j = 2, d = 3, s = 4, k = [2, 4, 5, 3, 1]

%Here j = 3, d = 3, s = 4, k = [2, 4, 5, 3, 1]

%Here j = 4, d = 3, s = 4, k = [2, 4, 5, 3, 1]

%Here j = 5, d = 3, s = 4, k = [2, 4, 5, 3, 1]

switch(k(j)) %Switches with value k(1) = 2

%Switches with value k(2) = 4

%Switches with value k(3) = 5

%Switches with value k(4) = 3

%Switches with value k(5) = 1

case {1, 2}

out1 = d + 4 % out1 = 7 will be printed. (Line4, 8)

case {3, 4}

out1 = 2*s % out1 = 8 will be printed. (Line5, 7)

otherwise

out1 = d + s % out1 = 7 will be printed. (Line6)

end

end

end

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