This set of MATLAB Questions and Answers for Entrance exams focuses on “Logical Expressions – 2”.

1. ‘=’ is a?

a) Relational operator

b) Arithmetic operator

c) Operational operator

d) Assignment operator

View Answer

Explanation: p=2 assigns the value 2 to the variable p. Hence, ‘=’ is an assignment operator. It doesn’t perform arithmetic operations so it isn’t an arithmetic operator. It isn’t a relational operator unlike ‘==’.

2. What is the output of the following code?

sin(pi)~=0

a) NaN

b) 0

c) 1

d) Error

View Answer

Explanation: sin(pi) is not equal to 0 since pi is represented as a floating point number in MATLAB. If pi was declared as a symbolic variable, the output would’ve been 0.

Output: 1

3. What is the output of the following code?

sin(Inf)~=NaN

a) 1

b) 0

c) Error

d) NaN

View Answer

Explanation: sin(Inf) is actually a number since the domain of sine is -infinity to infinity and the range is always -1 to 1. Hence, sin(Inf) is still a number- but it cannot be comprehended hence the value will be returned NaN. But in the above comparison, MATLAB will observe that sin(Inf) is still a number within -1 and 1 and hence, the output is 1.

4. What is the output of the following code?

log(0)==Inf

a) 1

b) 0

c) Error

d) Inf

View Answer

Explanation: log(0) is -Inf. This is why the output of the above code is 0.

Output: 0

5. What is the output of the following code?

and(sin(pi),112312)

a) 1

b) 0

c) 00

d) Error

View Answer

Explanation: sin(pi) won’t return 0 since pi is an in-built floating-point constant. If we had declared pi as symbolic, the output would’ve been 0.

6. The ~ is ______

a) Quaternary operator

b) Relational Operator

c) Arithmetic Operator

d) Unary Operator

View Answer

Explanation: ~ is a unary operator since the NOT function operates on only one operand. It isn’t a relational operator since it doesn’t do any comparison and it’s not an arithmetic operator since it doesn’t perform any arithmetic operation.

7. All logical operators operate on at least two operands.

a) True

b) False

View Answer

Explanation: The ‘ ~ ’ operator operates on one operand but it’s a logical operator. Hence, the statement is false.

8. What is the output of the following code?

NaN==Inf

a) 0

b) 1

c) Nan

d) Inf

View Answer

Explanation: Nan and Inf are two symbolic variables in MATLAB suggesting ‘Not a number’ and ‘Infinity’ respectively. These are not equal to each other and hence we will get a logical 0 when we enter this in MATLAB.

9. What is the output of the following code?

Sin(Inf)==NaN

a) 0

b) 1

c) Nan

d) Inf

View Answer

Explanation: If we type sin(Inf) in MATLAB, we will get NaN as an input because MATLAB cannot find the value of sin(Inf). But, MATLAB knows that sin(Inf) possesses a value, it cannot comprehend it but still it has a value. So, even though it will show NaN when we write sin(Inf), it will not give a logical 1 for the following code since sin(Inf) is still a number between 1 and -1.

10. The precedence of : operator is after | and before &.

a) True

b) False

View Answer

Explanation: The hierarchy for precedence of operators for the aforementioned operators is :, &, |. Hence the given statement is false.

11. What is the output of the following code?

~xor(and(1,0),~xor(and(1,0),0))

a) 0

b) 1

c) NaN

d) Error

View Answer

Explanation: and(1,0) is 0. ~xor(0,0,) is 1. But xor(1,0) is 1. Hence, ~xor(1,0) is 0.

Output: 0

12. The precedence of Transpose operation is ____________

a) after &

b) after |

c) before .^

d) after ^

View Answer

Explanation: The transpose operation has the highest precedence amongst all the aforementioned operators. The hierarchy is .’, .^, ^, &, |. Hence option before .^ is correct.

13. All relational operators operate on _______________

a) only real part of complex numbers

b) only imaginary part of complex numbers

c) complex numbers

d) numbers which are not complex

View Answer

Explanation: Some relational operators do not operate on the imaginary part of the complex numbers. But all relational operators operate on the real part of complex numbers.

14. What is the output of the following code?

any([])

a) 0

b) 1

c) NaN

d) Error

View Answer

Explanation: Since there are no elements in the input vector, it also means there are no non-zero elements in the vector. Hence, the logical result of the operation is 0.

15. What is the output of the following code?

all[1, 2, 3, NaN]

a) Error due to NaN

b) 1

c) 0

d) Syntactical Error

View Answer

Explanation: Even though the elements were declared within a vector, the syntax of the all() function is wrong since the vector should be present within a pair of parentheses. If the vector was given within a pair of parentheses, the result would’ve been 1. No error will be given due to NaN.

**Sanfoundry Global Education & Learning Series – MATLAB.**

To practice all areas of MATLAB for Entrance exams, __here is complete set of 1000+ Multiple Choice Questions and Answers__.