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

Given a function with two input arguments, x and n. Choose the correct if statem

ID: 3593130 • Letter: G

Question

Given a function with two input arguments, x and n. Choose the correct if statement that will give an error message when either input is an array.

A.

if x < -1

   y = 1;

elseif x <= 2

   y = x^2;

else

   y = 4;

end

B.

if x < -1

    y = 1;

elseif -1 <= x && x <= 2

    y = x^2;

else

    y = 4;

end

C.

if x < -1

   y = 1;

else

   if x <= 2

       y = x^2;

   else

       y = 4;

   end

end

D.

if x < -1

   y = 1;

end

if -1 <= x && x <= 2

  y = x^2;

end

if x > 2

   y = 4;

end

Explanation / Answer

x = [1.5 , 2.2, 3.3, 1.1];


% ########### set a #########
if x < -1
y = 1;
elseif x <= 2
y = x^2;
else
y = 4;
end
% ###########################


% ########### set b #########
if x < -1
y = 1;
elseif -1 <= x && x <= 2
y = x^2;
else
y = 4;
end
% ###########################


% ########### set c #########
if x < -1
y = 1;
else
if x <= 2
y = x^2;
else
y = 4;
end
end
% ###########################


% ########### set d #########
if x < -1
y = 1;
end

if -1 <= x && x <= 2
y = x^2;
end

if x > 2
y = 4;
end
% ###########################


disp(y)

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