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)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.