This set of MATLAB Multiple Choice Questions & Answers (MCQs) focuses on “Variables and Assignments”.
1. Which function is preferable to find the magnitude of a complex number?
d) MATLAB does not support complex arguments
Explanation: In the function sqrt(), we have to write the polynomial which shows the sum of squares of the real and imaginary part within the parentheses. But in abs(), we only have to enter the variable which we’ve used to define the complex number. So abs() is more preferred.
2. Which is an escape sequence constant?
Explanation: An escape sequence character constant is used in functions which are used to show output. ‘\b’ means backspace. ‘Esc’,‘/n’, are strings. ‘nargout’ is a pre-defined function in MATLAB.
3. All MATLAB computations are done in
a) Single Precision
b) Double Precision
c) Linear accuracy
d) Multi-level precision
Explanation: MATLAB stores any integer variable as a double data type of 64 bits. For single precision, the function is ‘single()’ but if not mentioned, the value will be stored in double precision.
4. Which symbol is used to initialise a variable?
Explanation: The symbol, ‘=’, is used to initialise a variable with a particular data type. ‘==’ checks whether the left hand side is equal to its’ right hand side. ‘init’ is a separate function in MATLAB.
5. Choose the correct option.
a) any() shows all the elements in a matrix while all() shows every element of a vector
b) any() is ‘true’ if elements in a vector is zero
c) all() is ‘true’ if every element in a vector is non zero
d) all() is ‘true’ if every element in a vector is 0
Explanation: ‘any()’ and ‘all()’ are pre-defined functions in MATLAB. The function ‘any()’ returns 1 if every element of the vector, mentioned within the parentheses, is non-zero. The function ‘all()’ returns 1 if any element of the vector is non-zero.
6. What operator helps in the transpose of a matrix?
a) “ .’ ”
b) “ ‘ ”
c) “./ ”
d) “ .\ ”
Explanation: ‘ .’ ‘ is used to get the transpose of a matrix. ‘ ‘ ‘ is used to get the complex conjugate transpose of a matrix. ‘ ./ ’ is used for the right division while the operator, ‘ .\’ is used for left division.
7. What is the difference between the expressions (9*1-8) & (9-1*8)?
a) Computational difference
b) Final results are different
c) No difference
d) Cannot be determined
Explanation: MATLAB follows a precedence of operators while doing any computation. So (9*1-8) is done like this: 9*1-8=9-8=9. But (9-1*8) is done like this: 9-1*8=9-8=1. Even though the answers are same, there is a computational difference between evaluation of the two expressions in MATLAB.
8. What is the output of the expression
Explanation: ‘NaN’ is a pre-defined variable in MATLAB. Whenever we try to evaluate an expression, if the expression contains sub-expressions which evaluate to infinity, the output produced is NaN. This denotes that the evaluation will not lead to number comprehensible by MATLAB.
9. The expression cos(90) is equal to1 in MATLAB.
Explanation: Any argument within the parentheses of the functions ‘sin()’, ‘cos()’ are taken to be in radians. If the argument is to be processed in degrees, the function is modified as sind() and cosd().
10. Evaluate the expression:
a=9/1*5/1; b=a*a/a*a; c=sind(30)+1/2; d=1-c; e=a+b*c-d
c) Error since sind() is a wrong function
Explanation: Following precedence of operators: ‘*’ > ’/’ > ‘+’ > ’–‘
a=9*5=45 ; b=a2/a*a=a*a=a2=2025 ; c=1/2+1/2=1 ; d=1-c=0 ;
Sanfoundry Global Education & Learning Series – MATLAB.
To practice all areas of MATLAB, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Get Free Certificate of Merit in MATLAB
- Participate in MATLAB Certification Contest
- Become a Top Ranker in MATLAB
- Take MATLAB Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10