This set of MATLAB Multiple Choice Questions & Answers (MCQs) focuses on “Sparse Matrices – 1”.
1. What is the attribute of sparse matrices?
d) no attribute
Explanation: The attribute of a sparse matrix will be sparse while the class of the attribute is double, by default. Hence, sparse is correct.
2. What is the output of the following code?
a) A m*n all zero sparse matrix
b) A m*n sparse matrix
c) Error due to syntax
d) Error in the input
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.
3. 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
Explanation: The sparse() command takes all kind of complex inputs. It is not biased by default.
4. 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
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.
5. To check whether the input matrix is sparse or not, we use the ________ command.
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.
6. A sparse identity matrix is generated by the ______ command.
Explanation: The correct command to generate a sparse identity matrix is the speye command. The issparse command checks whether an input matrix is a sparse matrix. Hence speye is correct.
7. What is the command used to generate a sparse normally generated matrix?
d) no such command
Explanation: The sprandn command uses the same random number generator as that of the randn command. The rest of the commands don’t exist.
8. What is the output of the following code?
A=[1 2 0 3; 2 8 4 1; sin(Inf) 2 3 4]; P=sparse(A); nnz(P)
c) Error while declaring A
d) Error while making sparse matrix
Explanation: The number of non-zero numbers in the A vector is 11. Sin(Inf) Is treated as NaN and holding a non-zero value since the range of sine is [-1,1]. There won’t be any error while declaring A or making the sparse matrix.
9. The non-zero elements in a sparse matrix are shown by the ______ command.
Explanation: The non-zeros command is used to get the non-zero elements present in the sparse matrix. The rest of the options are not defined in MATLAB.
10. What is the output of the following code?
A=[0 Inf/Inf 0 0; 2 9 7 0; sin(Inf) 8 0 0]; P=sparse(A);q=nmz(p); L=full(P);
a) l = a
b) lmemory > amemory
c) lmemory < amemory
d) lmemory != amemory
Explanation: The full command converts a sparse matrix into it’s original matrix. The space taken up by both the matrices in the memory are same. Hence, only l=a is correct.
11. The size of the sparse matrix will be ___ the original matrix.
b) greater than
c) less than
d) not equal to
Explanation: The sparse matrix stores the non-zero elements in the sparse matrix. The space taken up by the sparse matrix being very less than the original, the size of both the matrix will be same. Hence, only option equal is correct.
12. The maximum space allocated for sparse matrices is given by the ____ command.
d) no such command
Explanation: The nzmax is the command to find the maximum space allocated for sparse matrices. The maximum space is proportional to the number of non-zero elements in the original matrix.
13. The output of the following command is
a=[1 2 3;4 0 0;3 0 9]; spy(A)
a) a graph of sparsity
b) a pattern of sparsity
c) syntactical error
d) logical error
Explanation: The spy command generates the sparsity pattern of the sparse matrix which might be generated from the given matrix. The output will generate a pattern in a window which shows the position of non-zero elements occupying space.
14. The output of the following code is:
a=[pi/2 pi 3*pi]; spy[a]
a) Suppressed output
b) A pattern of sparsity
c) Syntactical error
d) Symbolic error
Explanation: The input to the spy command has to be within parentheses. Due to this, there will be a syntactical error in the above command.
15. The spy command takes in multiple matrices.
Explanation: The spy command does not take in multiple inputs. It will show the sparsity pattern of only input vector.
Sanfoundry Global Education & Learning Series – MATLAB.
To practice all areas of MATLAB, here is complete set of 1000+ Multiple Choice Questions and Answers.
Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!