11 Questions, 30 Minutes
Questions 1-8
What are the type and value of the variable R, after executing the given commands.
1)
b = 1; c = 0; d = 17; R = (b | c) & ~d;
2)
u = true; v = -17; R = u & v;
3)
v1 = 0; v2 = false; ww = 6; R = v1 & (v2|ww);
4)
r1 = pi/3; r2 = double(false); R = r2/r1;
5)
mass = 11; acc = -2; R = logical(mass*acc);
6)
X = 1; y = 0; z = 2; R = X & ~y & z;
7)
u = true; v = -17; w = 0; R = u & v & w;
8)
r1 = pi/3; r2 = false; R = r2/r1;
Questions 9-11
9)
Which numbers are displayed when the following MATLAB script is executed?
k = 1;
for j = 1:2:5
disp(k*2*j^2);
k = k + 1;
end
10)
How many times is the body of the while-loop executed in the script below?
L = 3;
count = 1;
myflag = true;
while myflag
if count > L
myflag = false;
end
count = count + 1
end
11)
What is the value of the variable y after executing the following MATLAB script?
y = myfunc(12,8)
function c = myfunc(a, y)
y = 17;
c = a - y;
end
Tip: Remember MATLAB's logical operations treat any non-zero value as true, and zero as false. Pay attention to operator precedence and data types!