MATLAB Questions and Answers Part-18

1. What is the output of the following code?
a) A 2*2 matrix of signed data type
b) A 2 element vector of signed data type
c) A 2 element vector
d) Error

Answer: d
Explanation: The rand command cannot take signed as a user-defined data type. The available data types are single and double. Hence, this will generate an error.

2. What is the default return type of the rand command?
a) Single
b) Double
c) Signed
d) Unsigned

Answer: b
Explanation: The default return type of the rand command is double. It can be changed to single by giving single as a string input to the rand command.

3. The rand command is provided by the __________
a) Parallel Computing Toolbox
b) Signal Processing Toolbox
c) Symbolic Math Toolbox
d) Does not exist

Answer: a
Explanation: The parallel Computing Toolbox contains the rand command in MATLAB. The rest of the options are incorrect.

4. What is the output of the following code?
a) Error
b) A normal distribution
c) A list of numbers selected randomly from the normal distribution
d) A normalized normal distribution

Answer: d
Explanation: If we don’t specify the mean and standard deviation of the normal distribution, the makedist command will generate a normal distribution which is normalized. This means the mean is 0 and a standard deviation is 1.

5. What is the output of the following code?
a) An array of random numbers selected from the normalized normal distribution
b) Error due to makedist
c) A random number from the normalized normal distribution
d) Error due to random

Answer: c
Explanation: There is no error in the above code. Firstly, a normalized normal distribution would be generated. Thereafter, the random command would select a value from it and display it in the command window.

6. What is the attribute of sparse matrices?
a) sparse
b) double
c) vector
d) no attribute

Answer: a
Explanation: The attribute of a sparse matrix will be sparse while the class of the attribute is double, by default. Hence, sparse is correct.

7. What is the output of the following code?
sparse[m n]
a) A m*n all zero sparse matrix
b) A m*n sparse matrix
c) Error due to syntax
d) Error in the input

Answer: c
Explanation: There are two errors in the above code. MATLAB would return the syntactical error due to [] since there should be a parenthesis. There is an error in the input since there should be a ‘ , ‘ between m an n.

8. The nature of complex input taken by the sparse() command is ______________
a) Only Imaginary part
b) Only positive imaginary part
c) Only negative real part
d) All of the mentioned

Answer: d
Explanation: The sparse() command takes all kind of complex inputs. It is not biased by default.

9. Which of the following can be the space taken up by a sparse matrix?
a) .25 megabytes
b) 600 megabytes
c) .5 GB
d) 450 megabytes

Answer: a
Explanation: The sparse matrix takes extremely small space from memory which is why it is so useful. The most plausible option amongst is .25 megabytes while the rest suggest pretty large amount of memory.

10. To check whether the input matrix is sparse or not, we use the ________ command.
a) issparse
b) besparse
c) ifsparse
d) sparse

Answer: a
Explanation: The correct command to check whether the input matrix is sparse or not is the issparse command. The sparse command generates a sparse matrix.